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"); 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,"); 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();"); diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerWebApplicationExtensions.cs similarity index 88% rename from src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServeWebApplicationExtensions.cs rename to src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerWebApplicationExtensions.cs index 5a5bb314..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; @@ -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,"); @@ -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, "{"); diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerHostGenerator.cs index 7796df9c..eebca68b 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, @@ -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 ContentGeneratorServeConfigureSwaggerOptions( - 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) { @@ -251,7 +228,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..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 ContentGeneratorServeConfigureSwaggerOptions( - 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) { @@ -204,7 +181,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/ContentGeneratorServeConfigureSwaggerOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs similarity index 86% rename from src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServeConfigureSwaggerOptions.cs rename to src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs index 674a6147..bb2b41de 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServeConfigureSwaggerOptions.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs @@ -1,12 +1,18 @@ namespace Atc.Rest.ApiGenerator.Framework.ContentGenerators.Server; -public class ContentGeneratorServeConfigureSwaggerOptions : IContentGenerator +public sealed class ContentGeneratorServerConfigureSwaggerDocOptions : IContentGenerator { + private readonly GeneratedCodeHeaderGenerator codeHeaderGenerator; + private readonly GeneratedCodeAttributeGenerator codeAttributeGenerator; private readonly ContentGeneratorServerSwaggerDocOptionsParameters parameters; - public ContentGeneratorServeConfigureSwaggerOptions( + public ContentGeneratorServerConfigureSwaggerDocOptions( + GeneratedCodeHeaderGenerator codeHeaderGenerator, + GeneratedCodeAttributeGenerator codeAttributeGenerator, ContentGeneratorServerSwaggerDocOptionsParameters parameters) { + this.codeHeaderGenerator = codeHeaderGenerator; + this.codeAttributeGenerator = codeAttributeGenerator; this.parameters = parameters; } @@ -14,19 +20,21 @@ public string Generate() { var sb = new StringBuilder(); + sb.Append(codeHeaderGenerator.Generate()); sb.AppendLine($"namespace {parameters.Namespace}.Options;"); // TODO: Move to constant sb.AppendLine(); - sb.AppendLine("public class ConfigureSwaggerOptions : IConfigureOptions"); + sb.AppendLine(codeAttributeGenerator.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, "/// 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(4, "public ConfigureSwaggerDocOptions("); sb.AppendLine(8, "IApiVersionDescriptionProvider provider,"); sb.AppendLine(8, "IWebHostEnvironment environment)"); sb.AppendLine(4, "{"); @@ -34,17 +42,17 @@ public string Generate() 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(); + 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)"); diff --git a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerSwaggerDocOptions.cs b/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerSwaggerDocOptions.cs deleted file mode 100644 index 7a0d6330..00000000 --- a/src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerSwaggerDocOptions.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace Atc.Rest.ApiGenerator.Framework.ContentGenerators.Server; - -public sealed class ContentGeneratorServerSwaggerDocOptions : IContentGenerator -{ - private readonly GeneratedCodeHeaderGenerator codeHeaderGenerator; - private readonly GeneratedCodeAttributeGenerator codeAttributeGenerator; - private readonly ContentGeneratorServerSwaggerDocOptionsParameters parameters; - - public ContentGeneratorServerSwaggerDocOptions( - GeneratedCodeHeaderGenerator codeHeaderGenerator, - GeneratedCodeAttributeGenerator codeAttributeGenerator, - ContentGeneratorServerSwaggerDocOptionsParameters parameters) - { - this.codeHeaderGenerator = codeHeaderGenerator; - this.codeAttributeGenerator = codeAttributeGenerator; - this.parameters = parameters; - } - - public string Generate() - { - var sb = new StringBuilder(); - - sb.Append(codeHeaderGenerator.Generate()); - sb.AppendLine($"namespace {parameters.Namespace}.Options;"); // TODO: Move to constant - sb.AppendLine(); - sb.AppendLine(codeAttributeGenerator.Generate()); - sb.AppendLine("public class ConfigureSwaggerDocOptions : IConfigureOptions"); - sb.AppendLine("{"); - sb.AppendLine(4, "private readonly IApiVersionDescriptionProvider provider;"); - 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, "public ConfigureSwaggerDocOptions("); - sb.AppendLine(8, "IApiVersionDescriptionProvider provider)"); - sb.AppendLine(8, "=> this.provider = provider;"); - 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.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.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" }, }; 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; } 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(); 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