. net core first time swagger

Time:2020-1-27

Install nuget package = swashblock.aspnetcore

 

Add a registration generator to the startup.configureservices method

//Register the swagger generator and define one or more swagger documents
  services.AddSwaggerGen(c =>
  {
     c. Swaggerdoc ("V1", new info() {title = "test version", version = "V1"});
 
     c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
     c. Customschemaids (type = > type. Fullname); // solve the problem that the same class name will report an error
 
     c. Includexmlcomments (path. Combine (directory. Getcurrentdirectory(), "swaggerdemo. XML"); // comment the XML document to use
  });

 

 

If you need to use some comments for the display controller on the page, you can choose to generate output XML document file.

1591 some uncommented warnings may be dispensed with.

Note example:

 

—-

 

 

 

Add middleware service in the startup.configure method

//Enable middleware services to generate swagger as JSON endpoint
app.UseSwagger();

//Enable middleware service pair swagger UI, specify swagger JSON endpoint
app.UseSwaggerUI(c =>
{
      c.SwaggerEndpoint("/swagger/v1/swagger.json", "DemoAPI V1");
 });

 

After adding, you can build your own controller.

Note: the controller must be an API identified controller.

 

 

The methods inside must also have HTTP request protocol.

 

Last visit = / swagger / index.html

 

 

 

 

Learn the article from yilezhu = “click to enter the trans temporal transmission