Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can view the swagger ui for Azure API app

I am creating an Azure API app on Visual Studio 2015. when i hit browse and redirected to http://localhost:3012/ if i add swagger to the url nothing happens : http://localhost:3012/swagger

it seems I need to add the /docs/v1 for a full address : http://localhost:3012/swagger/docs/v1 . Shouldn't there be like an automatic URL routing when i add /swagger to load swagger page. Also, i am only able to view the json schema, if i browser to the UI http://localhost:3012/swagger/ui the page doesn't load.

The API app builds successfully. is there anything missing?

like image 365
Shankar Avatar asked Mar 30 '16 07:03

Shankar


People also ask

How do I view swagger UI?

Go to http://localhost:8000/ in your address bar. This address lets you view the local web server. By default, web servers default to the index. html file in the directory, so it will show the Swagger UI file automatically.

Is Swagger supported in Azure?

SwaggerHub integrates with Azure API Management, which allows you to easily export your API definitions to Azure. This way you can design your APIs on SwaggerHub, then deploy your API design to your Azure API Management instance from SwaggerHub, keeping the APIs updated with any changes you make to the design.


2 Answers

In the configuration of your WebAPI project (SwaggerConfig.cs in the folder App_Start), you have to enable the Swagger UI. It is commented out as default behavior.

Just open the configuration, search for:

                /*
                    })
                .EnableSwaggerUi(c =>
                    {
                */

and disable the comments in the lines above and under it

like image 56
Pedro G. Dias Avatar answered Oct 08 '22 17:10

Pedro G. Dias


Pedro, above, has provided a perfect answer for enabling SwaggerUi. As for your question regarding the URL "swagger/docs/v1"

This is the default URL used by Swashbuckle to return Swagger 2.0 JSON metadata for the API

The SwaggerConfig.cs file is created when you install the Swashbuckle package in a project. You can find it in the folder "App_Start" . It provides a number of ways to configure Swashbuckle. I haven't checked if you can change that default URL or do URL rerouting for it.

Edited:

The default route templates for the Swagger docs and swagger-ui are "swagger/docs/{apiVersion}" and "swagger/ui/{*assetPath}" respectively. You can change these so long as the provided templates include the relevant route parameters - {apiVersion} and {*assetPath}. For example: the URL to swagger-ui will be myswag/index.

httpConfiguration .EnableSwagger("docs/{apiVersion}/swagger", c => c.SingleApiVersion("v1", "A title for your API"))

.EnableSwaggerUi("myswag/{*assetPath}");

You can read more about it here in the GitHub repo: https://github.com/domaindrivendev/Swashbuckle

like image 3
Rami Sarieddine Avatar answered Oct 08 '22 15:10

Rami Sarieddine