diff --git a/.gitignore b/.gitignore index 8693eb3..b20040b 100644 --- a/.gitignore +++ b/.gitignore @@ -340,4 +340,5 @@ ASALocalRun/ # BeatPulse healthcheck temp database healthchecksdb -.ionide \ No newline at end of file +.ionide +build.fsx.lock diff --git a/build.fsx.lock b/build.fsx.lock new file mode 100644 index 0000000..4126e00 --- /dev/null +++ b/build.fsx.lock @@ -0,0 +1,5 @@ +STORAGE: NONE +RESTRICTION: || (== net6.0) (== netstandard2.0) +NUGET + remote: https://api.nuget.org/v3/index.json + FSharp.Core (10.1.201) diff --git a/paket.lock b/paket.lock index 48558e1..95a4ac7 100644 --- a/paket.lock +++ b/paket.lock @@ -8,10 +8,10 @@ NUGET Microsoft.Bcl.AsyncInterfaces (10.0.5) - restriction: || (>= net462) (&& (< net6.0) (>= netstandard2.0)) System.Threading.Tasks.Extensions (>= 4.6.3) - restriction: || (>= net462) (&& (>= netstandard2.0) (< netstandard2.1)) Microsoft.NETCore.Platforms (7.0.4) - restriction: >= net461 - Microsoft.OpenApi (2.7) + Microsoft.OpenApi (2.7.1) System.Text.Json (>= 8.0.5) - restriction: >= netstandard2.0 - Microsoft.OpenApi.YamlReader (2.7) - Microsoft.OpenApi (>= 2.7) - restriction: >= netstandard2.0 + Microsoft.OpenApi.YamlReader (2.7.1) + Microsoft.OpenApi (>= 2.7.1) - restriction: >= netstandard2.0 SharpYaml (>= 2.1.4) - restriction: >= netstandard2.0 System.Text.Json (>= 8.0.5) - restriction: >= netstandard2.0 NETStandard.Library (2.0.3) - restriction: >= net461 @@ -45,8 +45,8 @@ NUGET YamlDotNet (16.3) GITHUB remote: fsprojects/FSharp.TypeProviders.SDK - src/ProvidedTypes.fs (821de018b4fad3c9f8b4e2b743b99b86ff4e475f) - src/ProvidedTypes.fsi (821de018b4fad3c9f8b4e2b743b99b86ff4e475f) + src/ProvidedTypes.fs (dffd529ffef00434598f462f9f845561f49c2e9a) + src/ProvidedTypes.fsi (dffd529ffef00434598f462f9f845561f49c2e9a) remote: fsprojects/FSharp.Data src/FSharp.Data.Runtime.Utilities/NameUtils.fs (00034f9ae8b1803c296261d82dead736428e50d9) src/FSharp.Data.Runtime.Utilities/Pluralizer.fs (00034f9ae8b1803c296261d82dead736428e50d9) @@ -452,7 +452,7 @@ NUGET Microsoft.Extensions.Options (>= 10.0.5) Microsoft.Net.Http.Headers (10.0.5) Microsoft.Extensions.Primitives (>= 10.0.5) - Microsoft.OpenApi (2.7) + Microsoft.OpenApi (2.7.1) System.Text.Json (>= 8.0.5) Newtonsoft.Json (13.0.4) Newtonsoft.Json.Bson (1.0.3) @@ -569,7 +569,7 @@ NUGET Microsoft.NET.Test.Sdk (18.3) Microsoft.CodeCoverage (>= 18.3) Microsoft.TestPlatform.TestHost (>= 18.3) - Microsoft.OpenApi (2.7) + Microsoft.OpenApi (2.7.1) System.Text.Json (>= 8.0.5) Microsoft.Testing.Extensions.Telemetry (2.1) Microsoft.ApplicationInsights (>= 2.23) diff --git a/tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs b/tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs index ece4c0a..99e980e 100644 --- a/tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs +++ b/tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs @@ -1,7 +1,6 @@ -module SwaggerProvider.Tests.V3TypeMappingTests +module SwaggerProvider.Tests.v3.Schema.TypeMappingTests open System -open System.IO open Microsoft.OpenApi.Reader open SwaggerProvider.Internal.v3.Compilers open Xunit @@ -39,13 +38,29 @@ components: let readResult = Microsoft.OpenApi.OpenApiDocument.Parse(schemaStr, settings = settings) - let schema = readResult.Document + // Ensure the schema was parsed successfully before using it + match readResult.Diagnostic with + | null -> () + | diagnostic when diagnostic.Errors |> Seq.isEmpty |> not -> + let errorText = + diagnostic.Errors + |> Seq.map string + |> String.concat Environment.NewLine + + failwithf "Failed to parse OpenAPI schema:%s%s" Environment.NewLine errorText + | _ -> () + + let schema = + match readResult.Document with + | null -> failwith "Failed to parse OpenAPI schema: Document is null." + | doc -> doc let defCompiler = DefinitionCompiler(schema, false) let opCompiler = OperationCompiler(schema, defCompiler, true, false, true) opCompiler.CompileProvidedClients(defCompiler.Namespace) let types = defCompiler.Namespace.GetProvidedTypes() + let testType = types |> List.find(fun t -> t.Name = "TestType") match testType.GetDeclaredProperty("Value") with @@ -118,7 +133,8 @@ let ``required string byte format maps to byte array``() = let ty = compilePropertyType " type: string\n format: byte\n" true // DefinitionCompiler creates a rank-1 explicit array via MakeArrayType(1) - ty |> shouldEqual(typeof.MakeArrayType(1)) + let expected = typeof.MakeArrayType(1) + ty |> shouldEqual expected [] let ``required string binary format maps to Stream``() = @@ -133,50 +149,55 @@ let ``required string binary format maps to Stream``() = let ``optional boolean maps to Option``() = let ty = compilePropertyType " type: boolean\n" false - ty |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + ty |> shouldEqual expected [] let ``optional integer maps to Option``() = let ty = compilePropertyType " type: integer\n" false - ty |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + ty |> shouldEqual expected [] let ``optional integer int64 maps to Option``() = let ty = compilePropertyType " type: integer\n format: int64\n" false - ty |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + ty |> shouldEqual expected [] let ``optional number maps to Option``() = let ty = compilePropertyType " type: number\n" false - ty - |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + ty |> shouldEqual expected [] let ``optional number double maps to Option``() = let ty = compilePropertyType " type: number\n format: double\n" false - ty - |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + ty |> shouldEqual expected [] let ``optional DateTimeOffset maps to Option``() = let ty = compilePropertyType " type: string\n format: date-time\n" false - ty - |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + + ty |> shouldEqual expected [] let ``optional Guid maps to Option``() = let ty = compilePropertyType " type: string\n format: uuid\n" false - ty |> shouldEqual(typedefof>.MakeGenericType(typeof)) + let expected = typedefof>.MakeGenericType(typeof) + ty |> shouldEqual expected // ── Optional reference types are NOT wrapped (they are already nullable) ───── @@ -184,7 +205,7 @@ let ``optional Guid maps to Option``() = let ``optional string is not wrapped in Option``() = let ty = compilePropertyType " type: string\n" false - // string is a reference type — not wrapped in Option even when non-required + // string is a reference type -- not wrapped in Option even when non-required ty |> shouldEqual typeof [] @@ -192,5 +213,6 @@ let ``optional byte array is not wrapped in Option``() = let ty = compilePropertyType " type: string\n format: byte\n" false - // byte[*] is a reference type — not wrapped in Option - ty |> shouldEqual(typeof.MakeArrayType(1)) + // byte[*] is a reference type -- not wrapped in Option + let expected = typeof.MakeArrayType(1) + ty |> shouldEqual expected