I have implemented API versioning, but Swagger document is not generating for v2. Anything is wrong here?
builder.Services.AddApiVersioning(config =>
{
// Specify the default API Version as 1.0
config.DefaultApiVersion = new ApiVersion(1, 0);
// If the client hasn't specified the API version in the request, use the default API version number
config.AssumeDefaultVersionWhenUnspecified = true;
// Advertise the API versions supported for the particular endpoint
config.ReportApiVersions = true;
config.ApiVersionReader = new UrlSegmentApiVersionReader();
});
I have implemented API versioning, but Swagger document is not generating for v2. Anything is wrong here?
builder.Services.AddApiVersioning(config => {
// Specify the default API Version as 1.0 config.DefaultApiVersion = new ApiVersion(1, 0); // If the client hasn't specified the API version in the request, use the default API version number config.AssumeDefaultVersionWhenUnspecified = true; // Advertise the API versions supported for the particular endpoint config.ReportApiVersions = true; config.ApiVersionReader = new UrlSegmentApiVersionReader(); });
builder.Services.AddVersionedApiExplorer(config => {
config.GroupNameFormat = "'V'VVV"; config.SubstituteApiVersionInUrl = true; });
internal static IServiceCollection AddOpenApiDocumentation(this IServiceCollection services, AppConfig settings) { if (settings.SwaggerSetting.Enable) { services.AddEndpointsApiExplorer(); var dict = new Dictionary<string, string>(); dict.Add(settings.SwaggerSetting.ApiScope, "Access the api");
// //services.AddSwaggerDocument((document,provider) => // //{ // // document.OperationProcessors.Add(new RequestBodyExampleProcessor(provider)); // // document.DocumentName = "v2"; // // document.PostProcess = doc => // // { // // doc.Info.Version = "v2"; // // }; // // document.ApiGroupNames = new[] { "v2" }; // // document.ResolveExternalXmlDocumentation = true; // // document.UseXmlDocumentation = true; // //});
}
internal static IApplicationBuilder UseOpenApiDocumentation(this IApplicationBuilder app, AppConfig settings) { if (settings.SwaggerSetting.Enable) { string path = "/apidoc/{documentName}/swagger.json"; app.UseOpenApi(p => { p.Path = path; });
}