.NET Core PROGRAMMING
Swashbuckle proposes some useful annotations to enrich documentation. This article describes how to enable annotations.
Prerequisites
How to configure swagger for asp.net core API?
Getting Started
Step 1: Install below package:
Swashbuckle.AspNetCore.Annotations
Step 2: Add below code inside ConfigureServices function in startup.cs file
services.AddSwaggerGen(c =>{c.EnableAnnotations();});
![](https://cdn-images-1.medium.com/max/800/1*yYKmI78w9um8YvaNFYvdqw.png)
How to add Operation Annotation
SwaggerOperation is a useful attribute where you can set the summary, description, id, and the tags of an individual request/route.
Example, how to set summary & description is shown below:
![](https://cdn-images-1.medium.com/max/800/1*6qNYqSXA3CQ4jDki2x8t4g.png)
Below image shows how summary and description will be displayed in swagger UI documentation:
![](https://cdn-images-1.medium.com/max/800/1*dgcDFa-Ct1L5MPp8jHMdyg.png)
How to add SwaggerResponse annotation:
SwaggerResponse is an attribute where you can set for each status code a description.
Example, how to set SwaggerResponse for different HTTP status codes is shown below:
![](https://cdn-images-1.medium.com/max/800/1*fASMIl1ctGte47TLgscL6A.png)
Below image shows how SwaggerResponse for different status codes will be displayed in swagger UI documentation:
![](https://cdn-images-1.medium.com/max/800/1*qEJO4K-Aq5emrjPEh62LwQ.png)
Thank you for reading. Keep visiting and share this in your network. Please put your thoughts and feedback in the comments section.