diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 53f13ff..af150dd 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] + os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: diff --git a/build.fsx b/build.fsx index c007612..1360514 100644 --- a/build.fsx +++ b/build.fsx @@ -114,7 +114,7 @@ Target.create "BuildTests" (fun _ -> dotnet "build" "SwaggerProvider.TestsAndDoc // Run the unit tests using test runner let runTests assembly = - dotnet "test" $"{assembly} -c Release --no-build" + dotnet $"{assembly}" "" Target.create "RunUnitTests" (fun _ -> runTests "tests/SwaggerProvider.Tests/bin/Release/net9.0/SwaggerProvider.Tests.dll") diff --git a/src/Common/AssemblyInfo.fs b/src/Common/AssemblyInfo.fs index ba1a45c..365ee54 100644 --- a/src/Common/AssemblyInfo.fs +++ b/src/Common/AssemblyInfo.fs @@ -5,13 +5,13 @@ open System.Reflection [] [] [] -[] -[] +[] +[] do () module internal AssemblyVersionInformation = let [] AssemblyTitle = "SwaggerProvider" let [] AssemblyProduct = "SwaggerProvider" let [] AssemblyDescription = "F# Type Provider for Swagger & Open API" - let [] AssemblyVersion = "2.1.3" - let [] AssemblyFileVersion = "2.1.3" + let [] AssemblyVersion = "2.2.0" + let [] AssemblyFileVersion = "2.2.0" diff --git a/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj b/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj index cebba28..3ae9ff2 100644 --- a/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj +++ b/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj @@ -1,6 +1,7 @@ + Exe net9.0 true true @@ -28,6 +29,7 @@ + APIs.guru.fs diff --git a/tests/SwaggerProvider.ProviderTests/v2/Swagger.GitHub.Tests.fs b/tests/SwaggerProvider.ProviderTests/v2/Swagger.GitHub.Tests.fs index 0aac943..df0e56a 100644 --- a/tests/SwaggerProvider.ProviderTests/v2/Swagger.GitHub.Tests.fs +++ b/tests/SwaggerProvider.ProviderTests/v2/Swagger.GitHub.Tests.fs @@ -9,6 +9,11 @@ open System.Net.Http [] let Schema = __SOURCE_DIRECTORY__ + "/../Schemas/v2/github.json" +[] +let UserAgent = + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + + [] let Host = "https://api.github.com" @@ -18,9 +23,8 @@ let github() = let client = GitHub.Client() client.HttpClient.BaseAddress <- Uri Host - "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405" - |> Headers.ProductInfoHeaderValue.Parse - |> client.HttpClient.DefaultRequestHeaders.UserAgent.Add + client.HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent) + |> ignore client @@ -32,9 +36,8 @@ let taskGitHub() = let client = TaskGitHub.Client() client.HttpClient.BaseAddress <- Uri Host - "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405" - |> Headers.ProductInfoHeaderValue.Parse - |> client.HttpClient.DefaultRequestHeaders.UserAgent.Add + client.HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", UserAgent) + |> ignore client diff --git a/tests/SwaggerProvider.ProviderTests/v2/Swagger.PetStore.Tests.fs b/tests/SwaggerProvider.ProviderTests/v2/Swagger.PetStore.Tests.fs index 46b333a..4c2001e 100644 --- a/tests/SwaggerProvider.ProviderTests/v2/Swagger.PetStore.Tests.fs +++ b/tests/SwaggerProvider.ProviderTests/v2/Swagger.PetStore.Tests.fs @@ -1,4 +1,4 @@ -module Swagger.PetStore.Tests +module Swagger.PetStore.Tests open SwaggerProvider open Swagger @@ -25,7 +25,7 @@ let ``Test provided Host property``() = let store = PetStore.Client() store.HttpClient.BaseAddress.ToString() - |> shouldEqual "https://petstore.swagger.io/v2/" + |> shouldEqual "https://petstore.swagger.io/" store.HttpClient.BaseAddress <- Uri "http://petstore.swagger.io/v3/" @@ -45,11 +45,11 @@ let ``Instantiate provided objects``() = let ``throw custom exceptions from async``() = task { try - let! _ = store.GetPetById(-142L) + let! _ = store.GetPetById(242L) failwith "Call should fail" with :? System.AggregateException as aex -> match aex.InnerException with - | :? OpenApiException as ex -> ex.Description |> shouldEqual "Pet not found" + | :? System.Net.Http.HttpRequestException as ex -> ex.Message |> shouldContainText "Not Found" | _ -> raise aex } @@ -57,12 +57,10 @@ let ``throw custom exceptions from async``() = let ``throw custom exceptions from task``() = task { try - let! _ = storeTask.GetPetById(-142L) + let! _ = storeTask.GetPetById(342L) failwith "Call should fail" - with :? System.AggregateException as aex -> - match aex.InnerException with - | :? OpenApiException as ex -> ex.Description |> shouldEqual "Pet not found" - | _ -> raise aex + with :? System.Net.Http.HttpRequestException as ex -> + ex.Message |> shouldContainText "Not Found" } [] @@ -76,7 +74,7 @@ let ``call provided methods``() = () let tag = PetStore.Tag(None, "foobar") - tag.ToString() |> shouldEqual "foobar" + tag.Name |> shouldEqual "foobar" let pet = PetStore.Pet("foo", [||], Some id) pet.ToString() |> shouldContainText(id.ToString()) @@ -102,7 +100,7 @@ let ``call provided methods``() = [] let ``create types with Nullable properties``() = let tag = PetStoreNullable.Tag(Nullable<_>(), "foobar") - tag.ToString() |> shouldEqual "foobar" + tag.Name |> shouldEqual "foobar" let tag2 = PetStoreNullable.Tag(Name = "foobar") tag2.ToString() |> shouldContainText "foobar" diff --git a/tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.ResourceControllers.Tests.fs b/tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.ResourceControllers.Tests.fs index abf0ef0..ea62b79 100644 --- a/tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.ResourceControllers.Tests.fs +++ b/tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.ResourceControllers.Tests.fs @@ -1,4 +1,4 @@ -module Swashbuckle.v2.ResourceControllersTests +module Swashbuckle.v2.ResourceControllersTests open Xunit open FsUnitTyped @@ -7,18 +7,18 @@ open Swashbuckle.v2.ReturnControllersTests [] let ``ResourceStringString Add and get from resource dictionary``() = task { - do! api.PutApiResourceStringString("lang", "F#") - do! api.GetApiResourceStringString("lang") |> asyncEqual "F#" + do! api.PutApiResourceStringString("language", "Fsharp") + do! api.GetApiResourceStringString("language") |> asyncEqual "Fsharp" } [] let ``ResourceStringString Update value in the resource dictionary``() = task { - do! api.PutApiResourceStringString("name", "Sergey") - do! api.GetApiResourceStringString("name") |> asyncEqual "Sergey" + do! api.PutApiResourceStringString("name2", "Sergey") + do! api.GetApiResourceStringString("name2") |> asyncEqual "Sergey" - do! api.PostApiResourceStringString("name", "Siarhei") - do! api.GetApiResourceStringString("name") |> asyncEqual "Siarhei" + do! api.PostApiResourceStringString("name2", "Siarhei") + do! api.GetApiResourceStringString("name2") |> asyncEqual "Siarhei" } let ``ResourceStringString Delete from the dictionary``() = diff --git a/tests/SwaggerProvider.ProviderTests/v3/Swagger.PetStore.Tests.fs b/tests/SwaggerProvider.ProviderTests/v3/Swagger.PetStore.Tests.fs index c71bc4c..1d3026d 100644 --- a/tests/SwaggerProvider.ProviderTests/v3/Swagger.PetStore.Tests.fs +++ b/tests/SwaggerProvider.ProviderTests/v3/Swagger.PetStore.Tests.fs @@ -1,4 +1,4 @@ -module Swagger.v3.PetStore.Tests +module Swagger.v3.PetStore.Tests open SwaggerProvider open Swagger @@ -59,10 +59,8 @@ let ``throw custom exceptions from task``() = try let! _ = storeTask.GetPetById(-142L) failwith "Call should fail" - with :? System.AggregateException as aex -> - match aex.InnerException with - | :? OpenApiException as ex -> ex.Description |> shouldEqual "Pet not found" - | _ -> raise aex + with :? OpenApiException as ex -> + ex.Description |> shouldEqual "Pet not found" } [] @@ -76,7 +74,7 @@ let ``call provided methods``() = () let tag = PetStore.Tag(None, "foobar") - tag.ToString() |> shouldEqual "foobar" + tag.Name |> shouldEqual "foobar" let pet = PetStore.Pet("foo", [||], Some id) pet.ToString() |> shouldContainText(id.ToString()) @@ -102,7 +100,7 @@ let ``call provided methods``() = [] let ``create types with Nullable properties``() = let tag = PetStoreNullable.Tag(Nullable<_>(), "foobar") - tag.ToString() |> shouldEqual "foobar" + tag.Name |> shouldEqual "foobar" let tag2 = PetStoreNullable.Tag(Name = "foobar") tag2.ToString() |> shouldContainText "foobar" diff --git a/tests/SwaggerProvider.ProviderTests/v3/Swashbuckle.NoContentControllers.Tests.fs b/tests/SwaggerProvider.ProviderTests/v3/Swashbuckle.NoContentControllers.Tests.fs new file mode 100644 index 0000000..f08f5eb --- /dev/null +++ b/tests/SwaggerProvider.ProviderTests/v3/Swashbuckle.NoContentControllers.Tests.fs @@ -0,0 +1,20 @@ +module Swashbuckle.v3.NoContentControllersTests + +open Xunit +open Swashbuckle.v3.ReturnControllersTests + +[] +let ``Test 204 with GET``() = + task { do! api.GetApiNoContent() } + +[] +let ``Test 204 with POST``() = + task { do! api.PostApiNoContent() } + +[] +let ``Test 204 with PUT``() = + task { do! api.PutApiNoContent() } + +[] +let ``Test 204 with DELETE``() = + task { do! api.DeleteApiNoContent() } diff --git a/tests/SwaggerProvider.Tests/Schema.Parser.Tests.fs b/tests/SwaggerProvider.Tests/Schema.Parser.Tests.fs index 2366edb..5867d93 100644 --- a/tests/SwaggerProvider.Tests/Schema.Parser.Tests.fs +++ b/tests/SwaggerProvider.Tests/Schema.Parser.Tests.fs @@ -76,7 +76,7 @@ let unsupportedSchemaPaths = |> List.filter(fun s -> s.IndexOf("unsupported") > 0) |> List.map(fun s -> [| box s |]) -[] +[] let ``Fail to parse`` file = let file = Path.Combine(rootFolder, file) shouldFail(fun () -> parserTestBody file |> Async.AwaitTask |> Async.RunSynchronously) diff --git a/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj b/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj index 2bb7d9b..3292314 100644 --- a/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj +++ b/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj @@ -1,6 +1,7 @@ + Exe net9.0 true diff --git a/tests/Swashbuckle.WebApi.Server/Controllers/NoContentControllers.fs b/tests/Swashbuckle.WebApi.Server/Controllers/NoContentControllers.fs new file mode 100644 index 0000000..c4b7b6b --- /dev/null +++ b/tests/Swashbuckle.WebApi.Server/Controllers/NoContentControllers.fs @@ -0,0 +1,32 @@ +namespace Swashbuckle.WebApi.Server.Controllers + +open Microsoft.AspNetCore.Mvc + +[] +[] +type NoContentController() = + inherit ControllerBase() + + [] + [] + [] + member x.Get() = + x.NoContent() + + [] + [] + [] + member x.Post() = + x.NoContent() + + [] + [] + [] + member x.Put() = + x.NoContent() + + [] + [] + [] + member x.Delete() = + x.NoContent() diff --git a/tests/Swashbuckle.WebApi.Server/Controllers/SpecialCasesControllers.fs b/tests/Swashbuckle.WebApi.Server/Controllers/SpecialCasesControllers.fs index 113ea91..717b141 100644 --- a/tests/Swashbuckle.WebApi.Server/Controllers/SpecialCasesControllers.fs +++ b/tests/Swashbuckle.WebApi.Server/Controllers/SpecialCasesControllers.fs @@ -1,8 +1,6 @@ namespace Swashbuckle.WebApi.Server.Controllers -open System open Microsoft.AspNetCore.Mvc -open Swagger.Internal [] [] diff --git a/tests/Swashbuckle.WebApi.Server/Controllers/ValuesController.fs b/tests/Swashbuckle.WebApi.Server/Controllers/ValuesController.fs index 156e7e0..29e8af0 100644 --- a/tests/Swashbuckle.WebApi.Server/Controllers/ValuesController.fs +++ b/tests/Swashbuckle.WebApi.Server/Controllers/ValuesController.fs @@ -1,10 +1,6 @@ namespace Swashbuckle.WebApi.Server.Controllers -open System -open System.Collections.Generic -open System.Linq -open System.Threading.Tasks -open Microsoft.AspNetCore.Mvc + (* //[] diff --git a/tests/Swashbuckle.WebApi.Server/Program.fs b/tests/Swashbuckle.WebApi.Server/Program.fs index 316fb2c..fe12b27 100644 --- a/tests/Swashbuckle.WebApi.Server/Program.fs +++ b/tests/Swashbuckle.WebApi.Server/Program.fs @@ -1,14 +1,8 @@ namespace Swashbuckle.WebApi.Server open System -open System.Collections.Generic -open System.IO -open System.Linq -open System.Threading.Tasks open Microsoft.AspNetCore open Microsoft.AspNetCore.Hosting -open Microsoft.Extensions.Configuration -open Microsoft.Extensions.Logging module Program = let exitCode = 0 diff --git a/tests/Swashbuckle.WebApi.Server/Startup.fs b/tests/Swashbuckle.WebApi.Server/Startup.fs index c8f3be2..1827251 100644 --- a/tests/Swashbuckle.WebApi.Server/Startup.fs +++ b/tests/Swashbuckle.WebApi.Server/Startup.fs @@ -3,7 +3,6 @@ namespace Swashbuckle.WebApi.Server open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Hosting -open Microsoft.AspNetCore.Mvc open Microsoft.Extensions.Configuration open Microsoft.Extensions.DependencyInjection open Microsoft.OpenApi.Models @@ -33,7 +32,7 @@ type Startup private () = |> ignore // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = + member this.Configure(app: IApplicationBuilder, _: IWebHostEnvironment) = app.UseDeveloperExceptionPage() |> ignore // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. //app.UseHsts() |> ignore @@ -59,4 +58,7 @@ type Startup private () = //app.UseHttpsRedirection() |> ignore app.UseRouting() |> ignore + app.UseEndpoints(fun endpoints -> endpoints.MapControllers() |> ignore) + |> ignore + member val Configuration: IConfiguration = null with get, set diff --git a/tests/Swashbuckle.WebApi.Server/Swashbuckle.WebApi.Server.fsproj b/tests/Swashbuckle.WebApi.Server/Swashbuckle.WebApi.Server.fsproj index d87181b..60e9dd5 100644 --- a/tests/Swashbuckle.WebApi.Server/Swashbuckle.WebApi.Server.fsproj +++ b/tests/Swashbuckle.WebApi.Server/Swashbuckle.WebApi.Server.fsproj @@ -13,6 +13,7 @@ +