
Lots of cool stuff I wish they would have included with the sample ASP.NET Core 5 Web API Project Template to make it a little more real-world. You will also want to lock down and correct which media types your API consumes and produces as well as which status codes it returns.
#Swagger editor visual studio code#
You will want to add proper XML Documentation to your code for sure, which will allow you to add more information to the generated OpenAPI Specifications Document and Swagger UI. If you're new to OpenAPI, Swagger UI, and Swashbuckle, there's a lot more that can be done to document ASP.NET Core Web API's. Developers who use Azure API Management have an opportunity to automatically import the APIs into Azure API Management during the publish flow" Going Further Swashbuckle to add Swagger for rich discovery and documentation for your API REST endpoints. "When ASP.NET Core API projects enable OpenAPI, the Visual Studio 2019 version 16.8 and later publishing automatically offer an additional step in the publishing flow. Visual Studio creates a new API App project and adds NuGet packages, such as: Newtsonsoft.Json for deserializing requests and serializing responses to and from API app. The reason Microsoft added OpenAPI support to the template is for this new feature in Visual Studio 2019 for Azure API Management.

Therefore, when you create a new ASP.NET Core 5 Web API and immediately run the project, the browser will open up to the Swagger UI, allowing you to explore and test the API. app.UseSwagger() Īpp.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApi v1")) Debug Launch SettingsĪnd last, you will notice that the debug launch settings have been set to open a browser to "swagger" to display the Swagger UI when the project is run. Swagger asks Web APIs to return a YAML or JSON that contains a detailed specification of the entire API. Swagger tools support automated documentation, code generation, and test-case generation. In the Configure method in the Startup.cs file you will see Swagger being added to the middleware pipeline. Swagger is a Web API specification document that helps developers design, build, document, and consume RESTful web services.

services.AddSwaggerGen(c =>Ĭ.SwaggerDoc("v1", new OpenApiInfo )

Swagger UI uses this document to populate a user interface that allows one to explore and test the ASP.NET Core Web API. In the ConfigureServices method in the Startup.cs file you will notice the configuration to create an OpenAPI Specifications Document. If you edit the project file of a new ASP.NET Core 5 Web API, you will notice the inclusion of the Swashbuckle.AspNetCore package. Microsoft is simply including Swashbuckle as part of the template and configuring it with some default settings for your project. This isn't so much a new built-in feature as it is a change in the ASP.NET Core 5 Web API Project Template. One of the new features mentioned in the ASP.NET Core 5 announcement is the "built-in" support for OpenAPI and Swagger UI in ASP.NET Core 5 Web API's.
