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:
2. Search for Swashbuckle and add nuget, as shown in the figure: SwaggerConfig configuration file will appear in the project, as shown in the figure:
3. Configure XML file, as shown in the figure: The
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:
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
this case, you only need to add c.DisableValidator(); in the SwaggerConfig configuration, as shown in the figure:
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:
start your swagger configuration