With multiple API versions Title and Description must be set for each route otherwise default values are taken
See original GitHub issueIn case of multiple API versions, the following setup in the configuration method doesn’t work for Title
and Description
properties.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSwaggerWithApiExplorer(config =>
{
config.GeneratorSettings.OperationProcessors.TryGet<ApiVersionProcessor>().IncludedVersions = new[] { "1.0" };
config.SwaggerRoute = "v1.0.json";
});
app.UseSwaggerWithApiExplorer(config =>
{
config.GeneratorSettings.OperationProcessors.TryGet<ApiVersionProcessor>().IncludedVersions = new[] { "2.0" };
config.SwaggerRoute = "v2.0.json";
});
app.UseSwaggerUi3(typeof(Startup).GetTypeInfo().Assembly, config =>
{
config.SwaggerRoutes.Add(new SwaggerUi3Route("v1.0", "/v1.0.json"));
config.SwaggerRoutes.Add(new SwaggerUi3Route("v2.0", "/v2.0.json"));
// These settings are not considered, instead each route takes default title and description
config.GeneratorSettings.Title = "My API Title";
config.GeneratorSettings.Description = "My API functionalities.";
});
}
To avoid default values you need to set on each of the individual configuration.
app.UseSwaggerWithApiExplorer(config =>
{
config.GeneratorSettings.OperationProcessors.TryGet<ApiVersionProcessor>().IncludedVersions = new[] { "1.0" };
config.SwaggerRoute = "v1.0.json";
config.GeneratorSettings.Title = "My API Title";
config.GeneratorSettings.Description = "My API functionalities.";
});
Please also refer to this.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
With multiple API versions Title and Description must be set ...
With multiple API versions Title and Description must be set for each route otherwise default values are taken #1525.
Read more >How to support multiple swagger files per version/group?
It should be simple enough to group and build endpoint URLs by API version and billing name, but you'll need two dropdown lists...
Read more >Different Methods of API Versioning & Routing in ASP.Net ...
Let's start with how to set up for new web API versioning. ... Ideally, we need to change the URL routes, otherwise, it...
Read more >Best practices for API versioning? [closed]
For example, if API v3.0 is the latest API version, the following two should be aliases (i.e. behave identically to all API requests):...
Read more >Attribute Routing in ASP.NET Web API 2
Web API 2 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you use
app.UseSwaggerUi3
with SwaggerRoutes, it only renders the UI with the given routes, GeneratorSettings are ignored and must be set on the otherUseSwaggerWithApiExplorer
registrations. Also the assembly is ignored as the registration does not actually generate a spec (only renders UI) - you can remove this parameter.I think we need to better document this…
Ref: https://stackoverflow.com/questions/51710388/nswag-net-core-api-versioning-configuration