Swagger API does not update documentation

I use the Swagger API to document my REST services. Previously, my controller method did not have informational comments, so the Swagger API did not show a description, but now even after updating comments such as I do not get a description of the method in the selected area.

/// <summary> /// Gets the consumer scores by retailer id and return id /// </summary> /// <param name="retailerId"></param> /// <param name="returnId"></param> /// <returns></returns> 

enter image description here

Did I miss something?

+6
source share
1 answer

In order for Swashbuckle to read your XML comments, you will need to include an XML documentation file for your target project. In addition to this, you will need to specify Swashbuckle in this file in your startup configuration.

From the Swashbuckle documentation :

Open the Properties dialog box for your project, go to the Build tab and make sure the XML Documentation File is checked. This will result in a file containing all the XML comments at build time.

At this point, any classes or methods that are NOT commented on by XML comments will trigger an assembly warning. To suppress this, enter the warning code "1591" in the "Alerts" field in the properties dialog box. *

Configure Swashbuckle to include XML comments in a file in the Swagger-generated JSON:

 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API - V1", Version = "v1" } ); var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "MyApi.xml"); c.IncludeXmlComments(filePath); } 

Annotate your actions with comments, comments, and response tags.

 /// <summary> /// Retrieves a specific product by unique id /// </summary> /// <remarks>Awesomeness!</remarks> /// <response code="200">Product created</response> /// <response code="400">Product has missing/invalid values</response> /// <response code="500">Oops! Can't create your product right now</response> [HttpGet("{id}")] [ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(typeof(IDictionary<string, string>), 400)] [ProducesResponseType(typeof(void), 500)] public Product GetById(int id) 

Rebuild your project to update the XML comment file and move to the Swagger JSON endpoint. Notice how the descriptions are mapped to the corresponding Swagger fields.

+7
source

Source: https://habr.com/ru/post/1265501/


All Articles