net learning: C# configure Swagger in WEBAPI

In the separate development of front and back ends, WEBAPI often requires front-end and back-end joint debugging, which involves interface documents, and you can use Swagger to directly generate interface documents in the code by writing all the code comments.
1. Create a WEBAPI project:
Insert picture description here
2. Search for Swashbuckle and add nuget, as shown in the figure: Insert picture description hereSwaggerConfig configuration file will appear in the project, as shown in the figure:
Insert picture description here
3. Configure XML file, as shown in the figure: The
Insert picture description here
Model layer definition entity is generally used in the interface, so it is also required Configure Model XML, the method is the same as above.
Fourth, add configuration in SwaggerConfig:
Insert picture description here
IncludeXmlComments can be configured multiple, so that the comments of the model layer are also displayed

Sometimes the interface will appear as shown in the figure, which has no effect on the interface, but it looks uncomfortable, as shown in the figure: In
Insert picture description here
this case, you only need to add c.DisableValidator(); in the SwaggerConfig configuration, as shown in the figure:
Insert picture description here
here, swagger configuration It has been completed, run the project to visit http:##/swagger/ui/index, you can see the effect, as shown in the figure: Insert picture description here
start your swagger configuration

Guess you like

Origin blog.csdn.net/weixin_41812784/article/details/98037685