question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With multiple API versions Title and Description must be set for each route otherwise default values are taken

See original GitHub issue

In 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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Aug 9, 2018

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 other UseSwaggerWithApiExplorer 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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found