4
votes

Using Swashbuckle in conjuntion with c.MultipleApiVersions((apiDesc, version) =>... the result is our swagger file resides at eg: https://host/api/swagger/docs/{version}. I would like to actually have the swagger file at https://host/api/{version}/swagger. Is it possible the I can set this up in my SwaggerConfig .EnableSwagger()?

This would allow for the following Urls :

http://host/api/v1/swagger/

http://host/api/v2/swagger/

Appreciate the help.

2

2 Answers

4
votes

Just for further references in asp.net core 2.2 it will lokk like this

app.UseSwagger(options =>
        {
            options.RouteTemplate = "docs/{documentName}/docs.json";

        });

        app.UseSwaggerUI(options =>
            {
                //Build a swagger endpoint for each discovered API version  
                foreach (var description in provider.ApiVersionDescriptions.OrderByDescending(x=>x.ApiVersion).AsList())
                {
                    options.SwaggerEndpoint($"/docs/{description.GroupName}/docs.json", description.GroupName);
                }
                options.RoutePrefix = "docs";
            }
        );

in which provider is IApiVersionDescriptionProvider injected by DI

4
votes

To do that way, you can update the swaggerconfig file as shown below:

.EnableSwagger("{apiVersion}/swagger", c =>
        {
            c.MultipleApiVersions(
                (vc) =>
                {
                    vc.Version("v2", "Swashbuckle Dummy API V2");
                    vc.Version("v1", "Swashbuckle Dummy API V1");
                });
        });