From 15c9a9693f6e3b3608535435f6d1d65233e32221 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 13:55:35 +0200 Subject: [PATCH 01/14] fix: remove generation of [Authorize] attribute on Endpoint classes, since this has no effect --- .../ContentGenerators/ContentGeneratorServerEndpoints.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerEndpoints.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerEndpoints.cs index 21382285..9491dfbe 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerEndpoints.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerEndpoints.cs @@ -35,13 +35,6 @@ public string Generate() sb.Append(codeDocumentationTagsGenerator.GenerateTags(0, parameters.DocumentationTags)); } - if (parameters.Authorization is not null) - { - sb.AppendLine(parameters.Authorization.UseAllowAnonymous - ? "[AllowAnonymous]" - : "[Authorize]"); - } - sb.AppendLine(codeAttributeGenerator.Generate()); sb.AppendLine($"public sealed class {parameters.ApiGroupName}EndpointDefinition : IEndpointDefinition"); From d2e1ce3036ba640a8c6471b5356ed62b0ece1dd3 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 13:57:28 +0200 Subject: [PATCH 02/14] chore: ensure WebApplicationExtensions.PatchHttpMethods is generated as collection-expression --- .../ContentGeneratorServeWebApplicationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs index 5a5bb314..32062c47 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs @@ -21,7 +21,7 @@ public string Generate() sb.AppendLine(); sb.AppendLine("public static class WebApplicationExtensions"); sb.AppendLine("{"); - sb.AppendLine(4, "private static readonly string[] PatchHttpMethods = { \"patch\" };"); + sb.AppendLine(4, "private static readonly string[] PatchHttpMethods = [\"patch\"];"); sb.AppendLine(); sb.AppendLine(4, "public static RouteHandlerBuilder MapPatch("); sb.AppendLine(8, "this WebApplication app,"); From 9d19a69c5c93edc882fb89395e8a7e6d42f6e083 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 14:01:32 +0200 Subject: [PATCH 03/14] fix: for minimal api, WebApplicationExtensions - ensure swagger is only avaiable for development --- .../ContentGeneratorServeWebApplicationExtensions.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs index 32062c47..5eaf66c1 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs @@ -39,6 +39,11 @@ public string Generate() sb.AppendLine(8, "this WebApplication app,"); sb.AppendLine(8, "string applicationName)"); sb.AppendLine(4, "{"); + sb.AppendLine(8, "if (!app.Environment.IsDevelopment())"); + sb.AppendLine(8, "{"); + sb.AppendLine(12, "return app;"); + sb.AppendLine(8, "}"); + sb.AppendLine(); sb.AppendLine(8, "app.UseSwagger();"); sb.AppendLine(8, "app.UseSwaggerUI(options =>"); sb.AppendLine(8, "{"); From 400caa2941c0b35b8b2b7de3141a7ca5c143cbb5 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 14:02:11 +0200 Subject: [PATCH 04/14] refactor: rename ContentGeneratorServeWebApplicationExtensions to ContentGeneratorServerWebApplicationExtensions --- ...s.cs => ContentGeneratorServerWebApplicationExtensions.cs} | 4 ++-- .../ProjectGenerator/ServerHostGenerator.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/{ContentGeneratorServeWebApplicationExtensions.cs => ContentGeneratorServerWebApplicationExtensions.cs} (95%) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerWebApplicationExtensions.cs similarity index 95% rename from src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs rename to src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerWebApplicationExtensions.cs index 5eaf66c1..76954079 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerWebApplicationExtensions.cs @@ -1,11 +1,11 @@ // ReSharper disable SwitchStatementMissingSomeEnumCasesNoDefault namespace Atc.Rest.ApiGenerator.Framework.Minimal.ContentGenerators; -public class ContentGeneratorServeWebApplicationExtensions : IContentGenerator +public class ContentGeneratorServerWebApplicationExtensions : IContentGenerator { private readonly ContentGeneratorBaseParameters parameters; - public ContentGeneratorServeWebApplicationExtensions( + public ContentGeneratorServerWebApplicationExtensions( ContentGeneratorBaseParameters parameters) { this.parameters = parameters; diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs index 7796df9c..ca4d2003 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs @@ -164,7 +164,7 @@ public void ScaffoldWebApplicationBuilderExtensions() public void ScaffoldWebApplicationExtensions( SwaggerThemeMode swaggerThemeMode) { - var contentGenerator = new ContentGenerators.ContentGeneratorServeWebApplicationExtensions( + var contentGenerator = new ContentGenerators.ContentGeneratorServerWebApplicationExtensions( new ContentGeneratorBaseParameters(Namespace: projectName)) { SwaggerThemeMode = swaggerThemeMode, From c6520ebad11477046a01e488d464b7f654b02430 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 14:22:47 +0200 Subject: [PATCH 05/14] refactor: rename ContentGeneratorServerSwaggerDocOptions to ContentGeneratorServerConfigureSwaggerDocOptions --- .../ProjectGenerator/ServerHostGenerator.cs | 2 +- .../ProjectGenerator/ServerHostGenerator.cs | 2 +- ...cs => ContentGeneratorServerConfigureSwaggerDocOptions.cs} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/{ContentGeneratorServerSwaggerDocOptions.cs => ContentGeneratorServerConfigureSwaggerDocOptions.cs} (93%) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs index ca4d2003..0321ec0f 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs @@ -251,7 +251,7 @@ public void GenerateConfigureSwaggerDocOptions() fullNamespace, openApiDocument.ToSwaggerDocOptionsParameters()); - var contentGenerator = new ContentGeneratorServerSwaggerDocOptions( + var contentGenerator = new ContentGeneratorServerConfigureSwaggerDocOptions( new GeneratedCodeHeaderGenerator(new GeneratedCodeGeneratorParameters(apiGeneratorVersion)), new GeneratedCodeAttributeGenerator(new GeneratedCodeGeneratorParameters(apiGeneratorVersion)), contentGeneratorServerSwaggerDocOptionsParameters); diff --git a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs index 1dcf64e1..ed12d945 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs @@ -204,7 +204,7 @@ public void GenerateConfigureSwaggerDocOptions() fullNamespace, openApiDocument.ToSwaggerDocOptionsParameters()); - var contentGenerator = new ContentGeneratorServerSwaggerDocOptions( + var contentGenerator = new ContentGeneratorServerConfigureSwaggerDocOptions( new GeneratedCodeHeaderGenerator(new GeneratedCodeGeneratorParameters(apiGeneratorVersion)), new GeneratedCodeAttributeGenerator(new GeneratedCodeGeneratorParameters(apiGeneratorVersion)), contentGeneratorServerSwaggerDocOptionsParameters); diff --git a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerSwaggerDocOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs similarity index 93% rename from src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerSwaggerDocOptions.cs rename to src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs index 7a0d6330..73817a10 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerSwaggerDocOptions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs @@ -1,12 +1,12 @@ namespace Atc.Rest.ApiGenerator.Framework.ContentGenerators.Server; -public sealed class ContentGeneratorServerSwaggerDocOptions : IContentGenerator +public sealed class ContentGeneratorServerConfigureSwaggerDocOptions : IContentGenerator { private readonly GeneratedCodeHeaderGenerator codeHeaderGenerator; private readonly GeneratedCodeAttributeGenerator codeAttributeGenerator; private readonly ContentGeneratorServerSwaggerDocOptionsParameters parameters; - public ContentGeneratorServerSwaggerDocOptions( + public ContentGeneratorServerConfigureSwaggerDocOptions( GeneratedCodeHeaderGenerator codeHeaderGenerator, GeneratedCodeAttributeGenerator codeAttributeGenerator, ContentGeneratorServerSwaggerDocOptionsParameters parameters) From 098ba4bd59c7d5083cac5720cbc0d878cfdfddca Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 14:23:18 +0200 Subject: [PATCH 06/14] feat: add / endpoint for minimal api, which responds OK --- .../ContentGenerators/ContentGeneratorServerProgram.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs index 9bda3dc6..ef658052 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs @@ -70,6 +70,8 @@ public string Generate() sb.AppendLine(); sb.AppendLine(8, "app.UseEndpointDefinitions();"); sb.AppendLine(); + sb.AppendLine(8, "app.MapGet(\"/\", () => TypedResults.Text(\"OK\", \"text/plain\")).ExcludeFromDescription();"); + sb.AppendLine(); sb.AppendLine(8, "app.UseGlobalErrorHandler();"); sb.AppendLine(); sb.AppendLine(8, "// Enabling the status code pages middleware, will allow Problem Details to be used in some extra non-exception related framework scenarios,"); From 2bbb401f441708d047dd35a87a326a2f9e4aa04b Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 14:45:09 +0200 Subject: [PATCH 07/14] fix: ensure proper generation of initial ServiceCollectionExtensions for API --- ...eratorServerServiceCollectionExtensions.cs | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerServiceCollectionExtensions.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerServiceCollectionExtensions.cs index b07e4378..504569c3 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerServiceCollectionExtensions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerServiceCollectionExtensions.cs @@ -22,29 +22,29 @@ public string Generate() sb.AppendLine(8, "this IServiceCollection services)"); sb.AppendLine(4, "{"); sb.AppendLine(8, "services.AddEndpointsApiExplorer();"); - sb.AppendLine(8, "services.AddApiVersioning("); - sb.AppendLine(16, "options =>"); - sb.AppendLine(16, "{"); - sb.AppendLine(20, "// Specify the default API Version"); - sb.AppendLine(20, "options.DefaultApiVersion = new ApiVersion(1, 0);"); + sb.AppendLine(8, "services"); + sb.AppendLine(12, ".AddApiVersioning(options =>"); + sb.AppendLine(12, "{"); + sb.AppendLine(16, "// Specify the default API Version"); + sb.AppendLine(16, "options.DefaultApiVersion = new ApiVersion(1, 0);"); sb.AppendLine(); - sb.AppendLine(20, "// If the client hasn't specified the API version in the request, use the default API version number"); - sb.AppendLine(20, "options.AssumeDefaultVersionWhenUnspecified = true;"); + sb.AppendLine(16, "// If the client hasn't specified the API version in the request, use the default API version number"); + sb.AppendLine(16, "options.AssumeDefaultVersionWhenUnspecified = true;"); sb.AppendLine(); - sb.AppendLine(20, "// reporting api versions will return the headers"); - sb.AppendLine(20, "// \"api-supported-versions\" and \"api-deprecated-versions\""); - sb.AppendLine(20, "options.ReportApiVersions = true;"); + sb.AppendLine(16, "// reporting api versions will return the headers"); + sb.AppendLine(16, "// \"api-supported-versions\" and \"api-deprecated-versions\""); + sb.AppendLine(16, "options.ReportApiVersions = true;"); sb.AppendLine(); - sb.AppendLine(20, "//// DEFAULT Version reader is QueryStringApiVersionReader();"); - sb.AppendLine(20, "//// clients request the specific version using the x-api-version header"); - sb.AppendLine(20, "//// Supporting multiple versioning scheme"); - sb.AppendLine(20, "options.ApiVersionReader = ApiVersionReader.Combine("); - sb.AppendLine(24, "new HeaderApiVersionReader(ApiVersionConstants.ApiVersionHeaderParameter),"); - sb.AppendLine(24, "new MediaTypeApiVersionReader(ApiVersionConstants.ApiVersionMediaTypeParameter),"); - sb.AppendLine(24, "new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameter),"); - sb.AppendLine(24, "new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameterShort),"); - sb.AppendLine(24, "new UrlSegmentApiVersionReader());"); - sb.AppendLine(16, "})"); + sb.AppendLine(16, "//// DEFAULT Version reader is QueryStringApiVersionReader();"); + sb.AppendLine(16, "//// clients request the specific version using the x-api-version header"); + sb.AppendLine(16, "//// Supporting multiple versioning scheme"); + sb.AppendLine(16, "options.ApiVersionReader = ApiVersionReader.Combine("); + sb.AppendLine(20, "new HeaderApiVersionReader(ApiVersionConstants.ApiVersionHeaderParameter),"); + sb.AppendLine(20, "new MediaTypeApiVersionReader(ApiVersionConstants.ApiVersionMediaTypeParameter),"); + sb.AppendLine(20, "new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameter),"); + sb.AppendLine(20, "new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameterShort),"); + sb.AppendLine(20, "new UrlSegmentApiVersionReader());"); + sb.AppendLine(12, "})"); sb.AppendLine(12, ".AddApiExplorer(options =>"); sb.AppendLine(12, "{"); sb.AppendLine(16, "// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service"); @@ -60,7 +60,8 @@ public string Generate() sb.AppendLine(4, "public static void ConfigureSwagger("); sb.AppendLine(8, "this IServiceCollection services)"); sb.AppendLine(4, "{"); - sb.AppendLine(8, "services.AddTransient, ConfigureSwaggerOptions>();"); + sb.AppendLine(8, "services.ConfigureOptions();"); + sb.AppendLine(); sb.AppendLine(8, "services.AddSwaggerGen(options =>"); sb.AppendLine(8, "{"); sb.AppendLine(12, "options.OperationFilter();"); From 3281f03bf4e0a74453cbfef680f2d5fd8740ec14 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 15:06:07 +0200 Subject: [PATCH 08/14] refactor: rename ContentGeneratorServeConfigureSwaggerOptions to ContentGeneratorServerConfigureSwaggerOptions --- .../ProjectGenerator/ServerHostGenerator.cs | 2 +- .../ProjectGenerator/ServerHostGenerator.cs | 2 +- ...ns.cs => ContentGeneratorServerConfigureSwaggerOptions.cs} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/{ContentGeneratorServeConfigureSwaggerOptions.cs => ContentGeneratorServerConfigureSwaggerOptions.cs} (98%) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs index 0321ec0f..1cbc04e0 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs @@ -190,7 +190,7 @@ public void ScaffoldConfigureSwaggerOptions() fullNamespace, openApiDocument.ToSwaggerDocOptionsParameters()); - var contentGenerator = new ContentGeneratorServeConfigureSwaggerOptions( + var contentGenerator = new ContentGeneratorServerConfigureSwaggerOptions( contentGeneratorServerSwaggerDocOptionsParameters); var content = contentGenerator.Generate(); diff --git a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs index ed12d945..9e880353 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs @@ -133,7 +133,7 @@ public void ScaffoldConfigureSwaggerOptions() fullNamespace, openApiDocument.ToSwaggerDocOptionsParameters()); - var contentGenerator = new ContentGeneratorServeConfigureSwaggerOptions( + var contentGenerator = new ContentGeneratorServerConfigureSwaggerOptions( contentGeneratorServerSwaggerDocOptionsParameters); var content = contentGenerator.Generate(); diff --git a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServeConfigureSwaggerOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs similarity index 98% rename from src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServeConfigureSwaggerOptions.cs rename to src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs index 674a6147..5f6bcab0 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServeConfigureSwaggerOptions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs @@ -1,10 +1,10 @@ namespace Atc.Rest.ApiGenerator.Framework.ContentGenerators.Server; -public class ContentGeneratorServeConfigureSwaggerOptions : IContentGenerator +public class ContentGeneratorServerConfigureSwaggerOptions : IContentGenerator { private readonly ContentGeneratorServerSwaggerDocOptionsParameters parameters; - public ContentGeneratorServeConfigureSwaggerOptions( + public ContentGeneratorServerConfigureSwaggerOptions( ContentGeneratorServerSwaggerDocOptionsParameters parameters) { this.parameters = parameters; From 6e63100990ce86d11a272b71c5d869c54f3cf41b Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 15:06:31 +0200 Subject: [PATCH 09/14] feat: bump Swashbuckle.AspNetCore in NugetPackageReferenceProvider from 6.6.2 to 6.7.0 --- .../Providers/NugetPackageReferenceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework/Providers/NugetPackageReferenceProvider.cs b/src/Atc.Rest.ApiGenerator.Framework/Providers/NugetPackageReferenceProvider.cs index 48139144..f6714ef8 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/Providers/NugetPackageReferenceProvider.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/Providers/NugetPackageReferenceProvider.cs @@ -28,7 +28,7 @@ public class NugetPackageReferenceProvider( { "Microsoft.NETCore.Platforms", "7.0.4" }, { "Microsoft.NET.Test.Sdk", "17.10.0" }, { "NSubstitute", "5.1.0" }, - { "Swashbuckle.AspNetCore", "6.6.2" }, + { "Swashbuckle.AspNetCore", "6.7.0" }, { "xunit", "2.8.1" }, { "xunit.runner.visualstudio", "2.8.1" }, }; From 06d05e98236df6e787fe7e6ac5d562bfba4bda47 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 15:18:48 +0200 Subject: [PATCH 10/14] feat: extend ContentGeneratorServerConfigureSwaggerDocOptions with proper code --- ...neratorServerConfigureSwaggerDocOptions.cs | 131 +++++++++++++++++- 1 file changed, 128 insertions(+), 3 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs index 73817a10..8b29bb90 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs @@ -27,18 +27,143 @@ public string Generate() sb.AppendLine("public class ConfigureSwaggerDocOptions : IConfigureOptions"); sb.AppendLine("{"); sb.AppendLine(4, "private readonly IApiVersionDescriptionProvider provider;"); + sb.AppendLine(4, "private readonly IWebHostEnvironment environment;"); sb.AppendLine(); sb.AppendLine(4, "/// "); sb.AppendLine(4, "/// Initializes a new instance of the class."); sb.AppendLine(4, "/// "); sb.AppendLine(4, "/// The provider used to generate Swagger documents."); + sb.AppendLine(4, "/// The environment."); sb.AppendLine(4, "public ConfigureSwaggerDocOptions("); - sb.AppendLine(8, "IApiVersionDescriptionProvider provider)"); - sb.AppendLine(8, "=> this.provider = provider;"); + sb.AppendLine(8, "IApiVersionDescriptionProvider provider,"); + sb.AppendLine(8, "IWebHostEnvironment environment)"); + sb.AppendLine(4, "{"); + sb.AppendLine(8, "this.provider = provider;"); + sb.AppendLine(8, "this.environment = environment;"); + sb.AppendLine(4, "}"); sb.AppendLine(); sb.AppendLine(4, "public void Configure("); sb.AppendLine(8, "SwaggerGenOptions options)"); - sb.AppendLine(8, "=> options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, \"xml\"));"); + sb.AppendLine(4, "{"); + sb.AppendLine(8, "foreach (var description in provider.ApiVersionDescriptions)"); + sb.AppendLine(8, "{"); + sb.AppendLine(12, "options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description));"); + sb.AppendLine(8, "}"); + sb.AppendLine(); + sb.AppendLine(8, "options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, \"xml\"));"); + sb.AppendLine(4, "}"); + + sb.AppendLine(); + sb.AppendLine(4, "private OpenApiInfo CreateInfoForApiVersion("); + sb.AppendLine(8, "ApiVersionDescription description)"); + sb.AppendLine(4, "{"); + + var description = string.Empty; + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.Description)) + { + description = parameters.SwaggerDocOptions.Description! + .Replace("\"", string.Empty, StringComparison.Ordinal) + .Replace("'", string.Empty, StringComparison.Ordinal) + .Trim(); + } + + sb.AppendLine(8, $"var text = new StringBuilder(\"{description}\");"); + sb.AppendLine(8, "var info = new OpenApiInfo"); + sb.AppendLine(8, "{"); + sb.AppendLine(12, "Title = $\"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}\","); + sb.AppendLine(12, "Version = description.ApiVersion.ToString(),"); + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactName) || + !string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactEmail) || + !string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactUrl)) + { + sb.AppendLine(12, "Contact = new OpenApiContact"); + sb.AppendLine(12, "{"); + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactName)) + { + sb.AppendLine(16, $"Name = \"{parameters.SwaggerDocOptions.ContactName}\","); + } + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactEmail)) + { + sb.AppendLine(16, $"Email = \"{parameters.SwaggerDocOptions.ContactEmail}\","); + } + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactUrl)) + { + sb.AppendLine(16, $"Url = new Uri(\"{parameters.SwaggerDocOptions.ContactUrl}\"),"); + } + + sb.AppendLine(12, "},"); + } + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.TermsOfService)) + { + sb.AppendLine(12, $"TermsOfService = new Uri(\"{parameters.SwaggerDocOptions.TermsOfService}\"),"); + } + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseName) || + !string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseUrl)) + { + sb.AppendLine(12, "License = new OpenApiLicense"); + sb.AppendLine(12, "{"); + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseName)) + { + sb.AppendLine(16, $"Name = \"{parameters.SwaggerDocOptions.LicenseName}\","); + } + + if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseUrl)) + { + sb.AppendLine(16, $"Url = new Uri(\"{parameters.SwaggerDocOptions.LicenseUrl}\"),"); + } + + sb.AppendLine(12, "},"); + } + + sb.AppendLine(8, "};"); + sb.AppendLine(); + sb.AppendLine(8, "if (description.IsDeprecated)"); + sb.AppendLine(8, "{"); + sb.AppendLine(12, "text.Append(\" This API version has been deprecated.\");"); + sb.AppendLine(8, "}"); + sb.AppendLine(); + sb.AppendLine(8, "if (description.SunsetPolicy is { } policy)"); + sb.AppendLine(8, "{"); + sb.AppendLine(12, "if (policy.Date is { } when)"); + sb.AppendLine(12, "{"); + sb.AppendLine(16, "text.Append(\" The API will be sunset on \")"); + sb.AppendLine(20, ".Append(when.Date.ToShortDateString())"); + sb.AppendLine(20, ".Append('.');"); + sb.AppendLine(12, "}"); + sb.AppendLine(); + sb.AppendLine(12, "if (policy.HasLinks)"); + sb.AppendLine(12, "{"); + sb.AppendLine(16, "text.AppendLine();"); + sb.AppendLine(); + sb.AppendLine(16, "foreach (var link in policy.Links)"); + sb.AppendLine(16, "{"); + sb.AppendLine(20, "if (link.Type != \"text/html\")"); + sb.AppendLine(20, "{"); + sb.AppendLine(24, "continue;"); + sb.AppendLine(20, "}"); + sb.AppendLine(); + sb.AppendLine(20, "text.AppendLine();"); + sb.AppendLine(); + sb.AppendLine(20, "if (link.Title.HasValue)"); + sb.AppendLine(20, "{"); + sb.AppendLine(24, "text.Append(link.Title.Value).Append(\": \");"); + sb.AppendLine(20, "}"); + sb.AppendLine(); + sb.AppendLine(20, "text.Append(link.LinkTarget.OriginalString);"); + sb.AppendLine(16, "}"); + sb.AppendLine(12, "}"); + sb.AppendLine(8, "}"); + sb.AppendLine(); + sb.AppendLine(8, "info.Description = text.ToString();"); + sb.AppendLine(); + sb.AppendLine(8, "return info;"); + sb.AppendLine(4, "}"); sb.Append('}'); return sb.ToString(); From 942106650d33506e213b16b3e0af65ba4cb0b67a Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 15:21:10 +0200 Subject: [PATCH 11/14] feat: remove scaffolding of ConfigureSwaggerOptions class --- .../ProjectGenerator/ServerHostGenerator.cs | 23 --- .../ProjectGenerator/ServerHostGenerator.cs | 23 --- ...tGeneratorServerConfigureSwaggerOptions.cs | 163 ------------------ .../ProjectGenerator/IServerHostGenerator.cs | 2 - .../Generators/ServerHostGenerator.cs | 2 - 5 files changed, 213 deletions(-) delete mode 100644 src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs index 1cbc04e0..eebca68b 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs @@ -181,29 +181,6 @@ public void ScaffoldWebApplicationExtensions( overrideIfExist: false); } - public void ScaffoldConfigureSwaggerOptions() - { - var fullNamespace = $"{projectName}"; - - var contentGeneratorServerSwaggerDocOptionsParameters = ContentGeneratorServerSwaggerDocOptionsParameterFactory - .Create( - fullNamespace, - openApiDocument.ToSwaggerDocOptionsParameters()); - - var contentGenerator = new ContentGeneratorServerConfigureSwaggerOptions( - contentGeneratorServerSwaggerDocOptionsParameters); - - var content = contentGenerator.Generate(); - - var contentWriter = new ContentWriter(logger); - contentWriter.Write( - projectPath, - projectPath.CombineFileInfo("Options", "ConfigureSwaggerOptions.cs"), - ContentWriterArea.Src, - content, - overrideIfExist: false); - } - public void ScaffoldProgramFile( SwaggerThemeMode swaggerThemeMode) { diff --git a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs index 9e880353..db5895de 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerHostGenerator.cs @@ -124,29 +124,6 @@ public void ScaffoldWebApplicationExtensions( SwaggerThemeMode swaggerThemeMode) => throw new NotSupportedException($"{nameof(ScaffoldWebApplicationExtensions)} is not supported for MVC"); - public void ScaffoldConfigureSwaggerOptions() - { - var fullNamespace = $"{projectName}"; - - var contentGeneratorServerSwaggerDocOptionsParameters = ContentGeneratorServerSwaggerDocOptionsParameterFactory - .Create( - fullNamespace, - openApiDocument.ToSwaggerDocOptionsParameters()); - - var contentGenerator = new ContentGeneratorServerConfigureSwaggerOptions( - contentGeneratorServerSwaggerDocOptionsParameters); - - var content = contentGenerator.Generate(); - - var contentWriter = new ContentWriter(logger); - contentWriter.Write( - projectPath, - projectPath.CombineFileInfo("Options", "ConfigureSwaggerOptions.cs"), - ContentWriterArea.Src, - content, - overrideIfExist: false); - } - public void ScaffoldProgramFile( SwaggerThemeMode swaggerThemeMode) { diff --git a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs deleted file mode 100644 index 5f6bcab0..00000000 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerOptions.cs +++ /dev/null @@ -1,163 +0,0 @@ -namespace Atc.Rest.ApiGenerator.Framework.ContentGenerators.Server; - -public class ContentGeneratorServerConfigureSwaggerOptions : IContentGenerator -{ - private readonly ContentGeneratorServerSwaggerDocOptionsParameters parameters; - - public ContentGeneratorServerConfigureSwaggerOptions( - ContentGeneratorServerSwaggerDocOptionsParameters parameters) - { - this.parameters = parameters; - } - - public string Generate() - { - var sb = new StringBuilder(); - - sb.AppendLine($"namespace {parameters.Namespace}.Options;"); // TODO: Move to constant - sb.AppendLine(); - sb.AppendLine("public class ConfigureSwaggerOptions : IConfigureOptions"); - sb.AppendLine("{"); - sb.AppendLine(4, "private readonly IApiVersionDescriptionProvider provider;"); - sb.AppendLine(4, "private readonly IWebHostEnvironment environment;"); - sb.AppendLine(); - sb.AppendLine(4, "/// "); - sb.AppendLine(4, "/// Initializes a new instance of the class."); - sb.AppendLine(4, "/// "); - sb.AppendLine(4, "/// The provider used to generate Swagger documents."); - sb.AppendLine(4, "/// The environment."); - sb.AppendLine(4, "public ConfigureSwaggerOptions("); - sb.AppendLine(8, "IApiVersionDescriptionProvider provider,"); - sb.AppendLine(8, "IWebHostEnvironment environment)"); - sb.AppendLine(4, "{"); - sb.AppendLine(8, "this.provider = provider;"); - sb.AppendLine(8, "this.environment = environment;"); - sb.AppendLine(4, "}"); - sb.AppendLine(); - sb.AppendLine(4, "/// "); - sb.AppendLine(4, "public void Configure("); - sb.AppendLine(8, "SwaggerGenOptions options)"); - sb.AppendLine(4, "{"); - sb.AppendLine(8, "// Add a swagger document for each discovered API version"); - sb.AppendLine(8, "// note: you might choose to skip or document deprecated API versions differently"); - sb.AppendLine(8, "foreach (var description in provider.ApiVersionDescriptions)"); - sb.AppendLine(8, "{"); - sb.AppendLine(12, "options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description));"); - sb.AppendLine(8, "}"); - sb.AppendLine(4, "}"); - sb.AppendLine(); - sb.AppendLine(4, "private OpenApiInfo CreateInfoForApiVersion("); - sb.AppendLine(8, "ApiVersionDescription description)"); - sb.AppendLine(4, "{"); - - var description = string.Empty; - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.Description)) - { - description = parameters.SwaggerDocOptions.Description! - .Replace("\"", string.Empty, StringComparison.Ordinal) - .Replace("'", string.Empty, StringComparison.Ordinal) - .Trim(); - } - - sb.AppendLine(8, $"var text = new StringBuilder(\"{description}\");"); - sb.AppendLine(8, "var info = new OpenApiInfo"); - sb.AppendLine(8, "{"); - sb.AppendLine(12, "Title = $\"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}\","); - sb.AppendLine(12, "Version = description.ApiVersion.ToString(),"); - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactName) || - !string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactEmail) || - !string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactUrl)) - { - sb.AppendLine(12, "Contact = new OpenApiContact"); - sb.AppendLine(12, "{"); - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactName)) - { - sb.AppendLine(16, $"Name = \"{parameters.SwaggerDocOptions.ContactName}\","); - } - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactEmail)) - { - sb.AppendLine(16, $"Email = \"{parameters.SwaggerDocOptions.ContactEmail}\","); - } - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.ContactUrl)) - { - sb.AppendLine(16, $"Url = new Uri(\"{parameters.SwaggerDocOptions.ContactUrl}\"),"); - } - - sb.AppendLine(12, "},"); - } - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.TermsOfService)) - { - sb.AppendLine(12, $"TermsOfService = new Uri(\"{parameters.SwaggerDocOptions.TermsOfService}\"),"); - } - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseName) || - !string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseUrl)) - { - sb.AppendLine(12, "License = new OpenApiLicense"); - sb.AppendLine(12, "{"); - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseName)) - { - sb.AppendLine(16, $"Name = \"{parameters.SwaggerDocOptions.LicenseName}\","); - } - - if (!string.IsNullOrWhiteSpace(parameters.SwaggerDocOptions.LicenseUrl)) - { - sb.AppendLine(16, $"Url = new Uri(\"{parameters.SwaggerDocOptions.LicenseUrl}\"),"); - } - - sb.AppendLine(12, "},"); - } - - sb.AppendLine(8, "};"); - sb.AppendLine(); - sb.AppendLine(8, "if (description.IsDeprecated)"); - sb.AppendLine(8, "{"); - sb.AppendLine(12, "text.Append(\" This API version has been deprecated.\");"); - sb.AppendLine(8, "}"); - sb.AppendLine(); - sb.AppendLine(8, "if (description.SunsetPolicy is { } policy)"); - sb.AppendLine(8, "{"); - sb.AppendLine(12, "if (policy.Date is { } when)"); - sb.AppendLine(12, "{"); - sb.AppendLine(16, "text.Append(\" The API will be sunset on \")"); - sb.AppendLine(20, ".Append(when.Date.ToShortDateString())"); - sb.AppendLine(20, ".Append('.');"); - sb.AppendLine(12, "}"); - sb.AppendLine(); - sb.AppendLine(12, "if (policy.HasLinks)"); - sb.AppendLine(12, "{"); - sb.AppendLine(16, "text.AppendLine();"); - sb.AppendLine(); - sb.AppendLine(16, "foreach (var link in policy.Links)"); - sb.AppendLine(16, "{"); - sb.AppendLine(20, "if (link.Type != \"text/html\")"); - sb.AppendLine(20, "{"); - sb.AppendLine(24, "continue;"); - sb.AppendLine(20, "}"); - sb.AppendLine(); - sb.AppendLine(20, "text.AppendLine();"); - sb.AppendLine(); - sb.AppendLine(20, "if (link.Title.HasValue)"); - sb.AppendLine(20, "{"); - sb.AppendLine(24, "text.Append(link.Title.Value).Append(\": \");"); - sb.AppendLine(20, "}"); - sb.AppendLine(); - sb.AppendLine(20, "text.Append(link.LinkTarget.OriginalString);"); - sb.AppendLine(16, "}"); - sb.AppendLine(12, "}"); - sb.AppendLine(8, "}"); - sb.AppendLine(); - sb.AppendLine(8, "info.Description = text.ToString();"); - sb.AppendLine(); - sb.AppendLine(8, "return info;"); - sb.AppendLine(4, "}"); - sb.Append('}'); - - return sb.ToString(); - } -} \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerHostGenerator.cs index 69f2ce76..0ae13a4e 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerHostGenerator.cs @@ -28,8 +28,6 @@ void ScaffoldWebApplicationExtensions( void GenerateConfigureSwaggerDocOptions(); - void ScaffoldConfigureSwaggerOptions(); - void ScaffoldProgramFile( SwaggerThemeMode swaggerThemeMode); diff --git a/src/Atc.Rest.ApiGenerator/Generators/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator/Generators/ServerHostGenerator.cs index 7e03d8ce..deecb638 100644 --- a/src/Atc.Rest.ApiGenerator/Generators/ServerHostGenerator.cs +++ b/src/Atc.Rest.ApiGenerator/Generators/ServerHostGenerator.cs @@ -110,7 +110,6 @@ public async Task Generate() projectOptions.ApiOptions.Generator.SwaggerThemeMode); serverHostGeneratorMvc.ScaffoldStartupFile(); serverHostGeneratorMvc.ScaffoldWebConfig(); - serverHostGeneratorMvc.ScaffoldConfigureSwaggerOptions(); serverHostGeneratorMvc.GenerateConfigureSwaggerDocOptions(); @@ -149,7 +148,6 @@ public async Task Generate() serverHostGeneratorMinimalApi.ScaffoldWebApplicationBuilderExtensions(); serverHostGeneratorMinimalApi.ScaffoldWebApplicationExtensions( projectOptions.ApiOptions.Generator.SwaggerThemeMode); - serverHostGeneratorMinimalApi.ScaffoldConfigureSwaggerOptions(); serverHostGeneratorMinimalApi.GenerateConfigureSwaggerDocOptions(); From c11fbc36da45371dda5d13ac6fa4055120b69348 Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 15:42:02 +0200 Subject: [PATCH 12/14] fix: ensure proper cref in ContentGeneratorServerConfigureSwaggerDocOptions --- .../Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs index 8b29bb90..bb2b41de 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs @@ -30,7 +30,7 @@ public string Generate() sb.AppendLine(4, "private readonly IWebHostEnvironment environment;"); sb.AppendLine(); sb.AppendLine(4, "/// "); - sb.AppendLine(4, "/// Initializes a new instance of the class."); + sb.AppendLine(4, "/// Initializes a new instance of the class."); sb.AppendLine(4, "/// "); sb.AppendLine(4, "/// The provider used to generate Swagger documents."); sb.AppendLine(4, "/// The environment."); From 2cdc7737663b8a33c68a2bc4d3163774c111a99a Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 15:42:24 +0200 Subject: [PATCH 13/14] fix: ensure proper using generation for auth in OpenApiDocumentExtensions --- .../Extensions/OpenApiDocumentExtensions.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator.OpenApi/Extensions/OpenApiDocumentExtensions.cs b/src/Atc.Rest.ApiGenerator.OpenApi/Extensions/OpenApiDocumentExtensions.cs index 515529ea..79065007 100644 --- a/src/Atc.Rest.ApiGenerator.OpenApi/Extensions/OpenApiDocumentExtensions.cs +++ b/src/Atc.Rest.ApiGenerator.OpenApi/Extensions/OpenApiDocumentExtensions.cs @@ -376,8 +376,7 @@ public static bool IsUsingRequiredForMicrosoftAspNetCoreAuthorization( continue; } - var isOperationAuthenticationRequired = - apiOperationPair.Value.Extensions.ExtractAuthenticationRequired(); + var isOperationAuthenticationRequired = apiOperationPair.Value.Extensions.ExtractAuthenticationRequired(); if (isOperationAuthenticationRequired is not null && isOperationAuthenticationRequired.Value) { return true; @@ -394,8 +393,8 @@ public static bool IsUsingRequiredForMicrosoftAspNetCoreAuthorization( var authenticationRoles = openApiPath.Value.Extensions.ExtractAuthorizationRoles(); var authenticationSchemes = openApiPath.Value.Extensions.ExtractAuthenticationSchemes(); - if (authenticationRoles is not null && authenticationRoles.Count > 0 && - authenticationSchemes is not null && authenticationSchemes.Count > 0) + if ((authenticationRoles is not null && authenticationRoles.Count > 0) || + (authenticationSchemes is not null && authenticationSchemes.Count > 0)) { return true; } From 6de22ae894294a1d9c4d36ec56ac5e0be9cd9bae Mon Sep 17 00:00:00 2001 From: Per Kops Date: Tue, 20 Aug 2024 16:01:28 +0200 Subject: [PATCH 14/14] test: update cli scenario tests after changes --- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../CustomersEndpointDefinition.verified.cs | 1 - .../UsersEndpointDefinition.verified.cs | 1 - .../ServiceCollectionExtensions.verified.cs | 43 ++++----- .../WebApplicationExtensions.verified.cs | 2 +- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ExAsyncEnumerable.Api/Program.verified.cs | 2 + .../CustomersEndpointDefinition.verified.cs | 1 - .../UsersEndpointDefinition.verified.cs | 1 - .../ServiceCollectionExtensions.verified.cs | 43 ++++----- .../WebApplicationExtensions.verified.cs | 2 +- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ExAsyncEnumerable.Api/Program.verified.cs | 2 + .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- .../ConfigureSwaggerDocOptions.verified.cs | 77 +++++++++++++++- .../ConfigureSwaggerOptions.verified.cs | 88 ------------------- 42 files changed, 1218 insertions(+), 1520 deletions(-) delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs delete mode 100644 test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 814489e4..9cff3972 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace DemoSample.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Demo Sample Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index e4da446a..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace DemoSample.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Demo Sample Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 814489e4..9cff3972 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace DemoSample.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Demo Sample Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index e4da446a..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace DemoSample.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Demo Sample Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 8eeb2eb1..7d28197e 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExAllResponseTypes.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Example With All Response Types Api"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index ac1c5a84..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExAllResponseTypes.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Example With All Response Types Api"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 8eeb2eb1..7d28197e 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExAllResponseTypes.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Example With All Response Types Api"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index ac1c5a84..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAllResponseTypes/VerifyServerAll/Mvc_WPD/src/ExAllResponseTypes.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExAllResponseTypes.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Example With All Response Types Api"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs index e1f5b949..33bf6acc 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs @@ -9,7 +9,6 @@ namespace ExAsyncEnumerable.Api.Generated.Endpoints; /// /// Endpoint definitions. /// -[Authorize] [GeneratedCode("ApiGenerator", "x.x.x.x")] public sealed class CustomersEndpointDefinition : IEndpointDefinition { diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs index 8aa9cb62..8003d44a 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs @@ -9,7 +9,6 @@ namespace ExAsyncEnumerable.Api.Generated.Endpoints; /// /// Endpoint definitions. /// -[Authorize] [GeneratedCode("ApiGenerator", "x.x.x.x")] public sealed class UsersEndpointDefinition : IEndpointDefinition { diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs index 74715279..25bcc86c 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs @@ -6,29 +6,29 @@ public static void ConfigureApiVersioning( this IServiceCollection services) { services.AddEndpointsApiExplorer(); - services.AddApiVersioning( - options => - { - // Specify the default API Version - options.DefaultApiVersion = new ApiVersion(1, 0); + services + .AddApiVersioning(options => + { + // Specify the default API Version + options.DefaultApiVersion = new ApiVersion(1, 0); - // If the client hasn't specified the API version in the request, use the default API version number - options.AssumeDefaultVersionWhenUnspecified = true; + // If the client hasn't specified the API version in the request, use the default API version number + options.AssumeDefaultVersionWhenUnspecified = true; - // reporting api versions will return the headers - // "api-supported-versions" and "api-deprecated-versions" - options.ReportApiVersions = true; + // reporting api versions will return the headers + // "api-supported-versions" and "api-deprecated-versions" + options.ReportApiVersions = true; - //// DEFAULT Version reader is QueryStringApiVersionReader(); - //// clients request the specific version using the x-api-version header - //// Supporting multiple versioning scheme - options.ApiVersionReader = ApiVersionReader.Combine( - new HeaderApiVersionReader(ApiVersionConstants.ApiVersionHeaderParameter), - new MediaTypeApiVersionReader(ApiVersionConstants.ApiVersionMediaTypeParameter), - new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameter), - new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameterShort), - new UrlSegmentApiVersionReader()); - }) + //// DEFAULT Version reader is QueryStringApiVersionReader(); + //// clients request the specific version using the x-api-version header + //// Supporting multiple versioning scheme + options.ApiVersionReader = ApiVersionReader.Combine( + new HeaderApiVersionReader(ApiVersionConstants.ApiVersionHeaderParameter), + new MediaTypeApiVersionReader(ApiVersionConstants.ApiVersionMediaTypeParameter), + new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameter), + new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameterShort), + new UrlSegmentApiVersionReader()); + }) .AddApiExplorer(options => { // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service @@ -44,7 +44,8 @@ public static void ConfigureApiVersioning( public static void ConfigureSwagger( this IServiceCollection services) { - services.AddTransient, ConfigureSwaggerOptions>(); + services.ConfigureOptions(); + services.AddSwaggerGen(options => { options.OperationFilter(); diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs index f73e2bd5..df8a3eea 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs @@ -2,7 +2,7 @@ public static class WebApplicationExtensions { - private static readonly string[] PatchHttpMethods = { "patch" }; + private static readonly string[] PatchHttpMethods = ["patch"]; public static RouteHandlerBuilder MapPatch( this WebApplication app, diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs index a6a1cf94..33ad3823 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExAsyncEnumerable.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index ad901a5e..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExAsyncEnumerable.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Program.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Program.verified.cs index 7f9973e3..0905347c 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Program.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WOPD/src/ExAsyncEnumerable.Api/Program.verified.cs @@ -45,6 +45,8 @@ public static void Main(string[] args) app.UseEndpointDefinitions(); + app.MapGet("/", () => TypedResults.Text("OK", "text/plain")).ExcludeFromDescription(); + app.UseGlobalErrorHandler(); // Enabling the status code pages middleware, will allow Problem Details to be used in some extra non-exception related framework scenarios, diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs index 0b02cbce..2a20e7af 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/CustomersEndpointDefinition.verified.cs @@ -9,7 +9,6 @@ namespace ExAsyncEnumerable.Api.Generated.Endpoints; /// /// Endpoint definitions. /// -[Authorize] [GeneratedCode("ApiGenerator", "x.x.x.x")] public sealed class CustomersEndpointDefinition : IEndpointDefinition { diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs index 75f31c2b..27d0926b 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api.Generated/Endpoints/UsersEndpointDefinition.verified.cs @@ -9,7 +9,6 @@ namespace ExAsyncEnumerable.Api.Generated.Endpoints; /// /// Endpoint definitions. /// -[Authorize] [GeneratedCode("ApiGenerator", "x.x.x.x")] public sealed class UsersEndpointDefinition : IEndpointDefinition { diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs index 74715279..25bcc86c 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/ServiceCollectionExtensions.verified.cs @@ -6,29 +6,29 @@ public static void ConfigureApiVersioning( this IServiceCollection services) { services.AddEndpointsApiExplorer(); - services.AddApiVersioning( - options => - { - // Specify the default API Version - options.DefaultApiVersion = new ApiVersion(1, 0); + services + .AddApiVersioning(options => + { + // Specify the default API Version + options.DefaultApiVersion = new ApiVersion(1, 0); - // If the client hasn't specified the API version in the request, use the default API version number - options.AssumeDefaultVersionWhenUnspecified = true; + // If the client hasn't specified the API version in the request, use the default API version number + options.AssumeDefaultVersionWhenUnspecified = true; - // reporting api versions will return the headers - // "api-supported-versions" and "api-deprecated-versions" - options.ReportApiVersions = true; + // reporting api versions will return the headers + // "api-supported-versions" and "api-deprecated-versions" + options.ReportApiVersions = true; - //// DEFAULT Version reader is QueryStringApiVersionReader(); - //// clients request the specific version using the x-api-version header - //// Supporting multiple versioning scheme - options.ApiVersionReader = ApiVersionReader.Combine( - new HeaderApiVersionReader(ApiVersionConstants.ApiVersionHeaderParameter), - new MediaTypeApiVersionReader(ApiVersionConstants.ApiVersionMediaTypeParameter), - new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameter), - new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameterShort), - new UrlSegmentApiVersionReader()); - }) + //// DEFAULT Version reader is QueryStringApiVersionReader(); + //// clients request the specific version using the x-api-version header + //// Supporting multiple versioning scheme + options.ApiVersionReader = ApiVersionReader.Combine( + new HeaderApiVersionReader(ApiVersionConstants.ApiVersionHeaderParameter), + new MediaTypeApiVersionReader(ApiVersionConstants.ApiVersionMediaTypeParameter), + new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameter), + new QueryStringApiVersionReader(ApiVersionConstants.ApiVersionQueryParameterShort), + new UrlSegmentApiVersionReader()); + }) .AddApiExplorer(options => { // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service @@ -44,7 +44,8 @@ public static void ConfigureApiVersioning( public static void ConfigureSwagger( this IServiceCollection services) { - services.AddTransient, ConfigureSwaggerOptions>(); + services.ConfigureOptions(); + services.AddSwaggerGen(options => { options.OperationFilter(); diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs index f73e2bd5..df8a3eea 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Extensions/WebApplicationExtensions.verified.cs @@ -2,7 +2,7 @@ public static class WebApplicationExtensions { - private static readonly string[] PatchHttpMethods = { "patch" }; + private static readonly string[] PatchHttpMethods = ["patch"]; public static RouteHandlerBuilder MapPatch( this WebApplication app, diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs index a6a1cf94..33ad3823 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExAsyncEnumerable.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index ad901a5e..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExAsyncEnumerable.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Program.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Program.verified.cs index 7f9973e3..0905347c 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Program.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/MinimalApi_WPD/src/ExAsyncEnumerable.Api/Program.verified.cs @@ -45,6 +45,8 @@ public static void Main(string[] args) app.UseEndpointDefinitions(); + app.MapGet("/", () => TypedResults.Text("OK", "text/plain")).ExcludeFromDescription(); + app.UseGlobalErrorHandler(); // Enabling the status code pages middleware, will allow Problem Details to be used in some extra non-exception related framework scenarios, diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs index a6a1cf94..33ad3823 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExAsyncEnumerable.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index ad901a5e..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WOPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExAsyncEnumerable.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs index a6a1cf94..33ad3823 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExAsyncEnumerable.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index ad901a5e..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExAsyncEnumerable/VerifyServerAll/Mvc_WPD/src/ExAsyncEnumerable.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExAsyncEnumerable.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("TestUnit AsyncEnumerable Ns Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 6b60fde6..80c49be3 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExGenericPagination.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Generic Pagination Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index e7b78b6b..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WOPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExGenericPagination.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Generic Pagination Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 6b60fde6..80c49be3 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExGenericPagination.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Generic Pagination Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index e7b78b6b..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExGenericPagination/VerifyServerAll/Mvc_WPD/src/ExGenericPagination.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExGenericPagination.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Generic Pagination Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs index ba28010f..2eade660 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExNsWithTask.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("TestUnit Task Ns Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index f638f424..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WOPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExNsWithTask.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("TestUnit Task Ns Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs index ba28010f..2eade660 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExNsWithTask.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("TestUnit Task Ns Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index f638f424..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExNsWithTask/VerifyServerAll/Mvc_WPD/src/ExNsWithTask.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExNsWithTask.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("TestUnit Task Ns Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 77150d11..27102e3e 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExUsers.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Demo Users Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index 5d5a388a..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WOPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExUsers.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Demo Users Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 77150d11..27102e3e 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace ExUsers.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder("Demo Users Api - SingleFileVersion"); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + Contact = new OpenApiContact + { + Name = "atc-net A/S", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index 5d5a388a..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/ExUsers/VerifyServerAll/Mvc_WPD/src/ExUsers.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace ExUsers.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder("Demo Users Api - SingleFileVersion"); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact - { - Name = "atc-net A/S", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 70790e0f..6bc72eaf 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace PetStore.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder(""); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + License = new OpenApiLicense + { + Name = "MIT", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index cd3fb219..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WOPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace PetStore.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder(""); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - License = new OpenApiLicense - { - Name = "MIT", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs index 70790e0f..6bc72eaf 100644 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs +++ b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerDocOptions.verified.cs @@ -10,16 +10,85 @@ namespace PetStore.Api.Options; public class ConfigureSwaggerDocOptions : IConfigureOptions { private readonly IApiVersionDescriptionProvider provider; + private readonly IWebHostEnvironment environment; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. + /// The environment. public ConfigureSwaggerDocOptions( - IApiVersionDescriptionProvider provider) - => this.provider = provider; + IApiVersionDescriptionProvider provider, + IWebHostEnvironment environment) + { + this.provider = provider; + this.environment = environment; + } public void Configure( SwaggerGenOptions options) - => options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + { + foreach (var description in provider.ApiVersionDescriptions) + { + options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); + } + + options.IncludeXmlComments(Path.ChangeExtension(GetType().Assembly.Location, "xml")); + } + + private OpenApiInfo CreateInfoForApiVersion( + ApiVersionDescription description) + { + var text = new StringBuilder(""); + var info = new OpenApiInfo + { + Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", + Version = description.ApiVersion.ToString(), + License = new OpenApiLicense + { + Name = "MIT", + }, + }; + + if (description.IsDeprecated) + { + text.Append(" This API version has been deprecated."); + } + + if (description.SunsetPolicy is { } policy) + { + if (policy.Date is { } when) + { + text.Append(" The API will be sunset on ") + .Append(when.Date.ToShortDateString()) + .Append('.'); + } + + if (policy.HasLinks) + { + text.AppendLine(); + + foreach (var link in policy.Links) + { + if (link.Type != "text/html") + { + continue; + } + + text.AppendLine(); + + if (link.Title.HasValue) + { + text.Append(link.Title.Value).Append(": "); + } + + text.Append(link.LinkTarget.OriginalString); + } + } + } + + info.Description = text.ToString(); + + return info; + } } \ No newline at end of file diff --git a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs b/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs deleted file mode 100644 index cd3fb219..00000000 --- a/test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/PetStore/VerifyServerAll/Mvc_WPD/src/PetStore.Api/Options/ConfigureSwaggerOptions.verified.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace PetStore.Api.Options; - -public class ConfigureSwaggerOptions : IConfigureOptions -{ - private readonly IApiVersionDescriptionProvider provider; - private readonly IWebHostEnvironment environment; - - /// - /// Initializes a new instance of the class. - /// - /// The provider used to generate Swagger documents. - /// The environment. - public ConfigureSwaggerOptions( - IApiVersionDescriptionProvider provider, - IWebHostEnvironment environment) - { - this.provider = provider; - this.environment = environment; - } - - /// - public void Configure( - SwaggerGenOptions options) - { - // Add a swagger document for each discovered API version - // note: you might choose to skip or document deprecated API versions differently - foreach (var description in provider.ApiVersionDescriptions) - { - options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); - } - } - - private OpenApiInfo CreateInfoForApiVersion( - ApiVersionDescription description) - { - var text = new StringBuilder(""); - var info = new OpenApiInfo - { - Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", - Version = description.ApiVersion.ToString(), - License = new OpenApiLicense - { - Name = "MIT", - }, - }; - - if (description.IsDeprecated) - { - text.Append(" This API version has been deprecated."); - } - - if (description.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - text.Append(" The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - foreach (var link in policy.Links) - { - if (link.Type != "text/html") - { - continue; - } - - text.AppendLine(); - - if (link.Title.HasValue) - { - text.Append(link.Title.Value).Append(": "); - } - - text.Append(link.LinkTarget.OriginalString); - } - } - } - - info.Description = text.ToString(); - - return info; - } -} \ No newline at end of file