Swagger use two: swagger configures multiple project annotations

Reprinted: https://www.cnblogs.com/eastday/p/6382613.html

 

It is very convenient to use the swagger test interface in the project and provide the interface to other people.

In the default configuration of swagger, only the annotations in the interface access layer are displayed by default, but many parameter descriptions are already in the entity layer? (as shown below) It is impossible to move the model in the entity layer again, like this There is too much repetition.

After some exploration, I found that swagger can support multiple paths at the same time.

1. Modify the configuration of swagger and add multiple file paths.        

    c.IncludeXmlComments(GetXmlControllersCommentsPath());
    c.IncludeXmlComments(GetXmlModelCommentsPath());

 

copy code
        private static string GetXmlControllersCommentsPath()
        {
            return System.IO.Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, "./App_Data/WebApi.XML");
        }
        private static string GetXmlModelCommentsPath()
        {
            return System.IO.Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, "./App_Data/Model.XML");
        }
copy code

2. Modify the location where the annotation document is saved when the entity layer is generated, and pay attention to the path to the interface access layer that needs to be modified.

Save, regenerate, and visit swagger again.

The annotation of the entity layer can be displayed, finished.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324836649&siteId=291194637