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?
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With