Search code examples
c#azureswaggerazure-web-app-serviceazure-api-apps

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?


Solution

  • 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