Swagger is a visual (or accessible) output tool that generates APIs and annotations, and can also be manually tested with our API, which solves the problem that the program doesn't want to write a document (haha).
Swashbuckle.aspnetcore is used to address API documentation under ASP., not only to display the UI, but also to test it on the UI.
If you use swagger in ASP. NET core, first install Swashbuckle.aspnetcore under NuGet, but now it's preview, make sure to tick "include pre-release version".
650) this.width=650; "title=" Swagger0001.png "src=" https://s2.51cto.com/wyfs02/M02/8E/3D/ Wkiol1i6h5nhomrtaagsbe-7llw806.png-wh_500x0-wm_3-wmp_4-s_1402315862.png "alt=" Wkiol1i6h5nhomrtaagsbe-7llw806.png-wh_50 "/>
There are also three references to add:
Swashbuckle.AspNetCore.SwaggerGen is the component that generates the swagger document
Swashbuckle.AspNetCore.Swagger: Is the component that generates the JSON API for the Swagger document
Swashbuckle.AspNetCore.SwaggerUI, a component that turns the JSON API into a page
Next, set the project properties, generate the-output node's XML documentation file tick, to ensure that the comment on the action to generate an XML document.
At the same time, the action in the Controller has to add the HTTP feature, so it is important to find an accurate API when generating swagger documents.
Next, we're going to use
to transpose Starup in swagger.
Public void configureservices (iservicecollection services) { services. Addmvc (); services. Addswaggergen (c => { c.swaggerdoc ("v1", new info { Title = "Swagger test", Version = "V1", Description = "Swagger Test Restful api ", termsofservice = "None", contact = new&nbsP contact { Name = "Gui Suewei", email = "[email protected]"              }, }); //set the XML comment document, note that the name must be the same as the project name var filepath = path.combine (platformservices.default.application.applicationbasepath, "SwaggerDemo.xml"); c.includexmlcomments (FilePath); //processing Complex name c.customschemaids ((type) => type.FullName); }); } public void configure (iapplicationbuilder app, ihostingenvironment env, iloggerfactory loggerfactory) { loggerfactory.addconsole (configuration.getsection ("Logging" ); loggerfactory.adddebug (); app. Usemvc (); app. Useswagger (c => { // Set JSON path c.RouteTemplate = "Docs/{documentname}" /swagger.json "; }); app. Useswaggerui (c => { Access Swagger ui routes, such as http://localhost: Port/docs c. routeprefix = "Docs "; c.swaggerendpoint ("/docs/v1/swagger.json ", " Swagger Test V1 ") //change UI style c.injectstylesheet ("/swagger-ui/custom.css"); //Introducing UI Changes Js c.injectoncompletejavascript ("/swagger-ui/custom.js"); }); }
For more Useswagger parameters and Useswaggerui parameters, refer to
Https://github.com/domaindrivendev/Swashbuckle.AspNetCore
The Custom.css and custom.js in the settings are as follows
Custom.css
. logo__title {font-weight:bold; font-size:0.8em;}
Custom.js
var titles=document.getelementsbyclassname ("Logo__title"); titles[0].innerhtml = "swagger test";
About beautify UI can run, view specific HTML Elements, then go to write CSS or JS
650) this.width=650; "Width=" "height=" 273 "title=" Swagger0002.png "style=" WIDTH:667PX;HEIGHT:386PX; "src=" https ://s5.51cto.com/wyfs02/m00/8e/3d/wkiol1i6h-esq63paaosweib8yg179.png-wh_500x0-wm_3-wmp_4-s_3236658431.png "alt=" Wkiol1i6h-esq63paaosweib8yg179.png-wh_50 "/>
This article is from the "Gui Suewei" blog, make sure to keep this source http://axzxs.blog.51cto.com/730810/1903143
Application of Swagger in ASP. 2