Creating your first ASP.NET Core Web API with Swashbuckle
June 11, 2016 by Anuraj
C# ASP.NET ASP.NET Core Documentation Swashbuckle
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.
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub