This post is to help developers on how to create interactive interface which represent their Restful API to provide a rich discovery, documentation and playground experience to their API consumers in ASP.NET Core Web API. First you need to create an ASP.NET Core web api project. In this post I am using the default project; I didn’t modified any code. Once you created the project you need add reference of Swashbuckle. For RC2 you need to add reference of 6.0.0-beta9 version.
Here is the project.json file.
And now you need modify startup file, to enable Swagger Generator and Swagger UI.Here the code for same. I am using the default urls, you can customize it. Here is the code. In the ConfigureServices method, Swagger Generator will be added and also configured.
And here the configure method where Swagger middleware added and configured.
Now you can run the api page @ http://localhost:8022/swagger/ui/index.html. Here is the screenshot.
Swagger also support traditional xml comments to be included in the documentation. In the ConfigureServices method. For xml documentation generation, enable xml documentation checkbox in the project properties.
And you can include xml comments in the ConfigureServices method like this.
This is one option to include xml comments, which is included in the Swagger generated API page.