Sebastian
Sebastian

Reputation: 151

How to customize swagger url?

I'm using swagger for my ASP.NET WebAPI Services. I want to show the documentation page on my base location.

When I want to show the Swagger UI I have to call this url: http://localhost:8080/swagger/ui/index or https://[your-url]/help/index

Is there any possibility that I load swagger on https://[your-url] and not at https://[your-url]/help/index

How can I get this working, without any redirect? I only want to host my services and want to show swagger ui on the base route.

Is this possible?

Upvotes: 1

Views: 2242

Answers (1)

Ignas
Ignas

Reputation: 4328

I've just tried, however swagger would crash due to an empty URL template. I am not aware of a way to implement this without redirects or URL rewrites.

You can configure base route and swagger URL using UseSwaggerUi() method.

        var baseRoute = "anything";
        var swaggerUrl = "/swagger/v1/swagger.json";
        app.UseSwagger();
        app.UseSwaggerUi(baseRoute, swaggerUrl);

The swagger URL would be: https://[your-url]/anything

This code snippet is from a .Net Core 1.0 application, however hopefully you can configure your Web API accordingly.

A possible option could be IIS URL rewrite rule.

Upvotes: 1

Related Questions