Swagger Features

Weekend pumping some time to put Swagger looked at, here to write articles about the summary. Swagger's official website has an online demo, the online experience. We can also download the source code , execute dist \ index.html file, and the official website you can get the same functionality demo, do not need to set up the server will be able to use.

    

View from the network request and found that it requested a file named swagger.json of.    

    

The basic scheme is a document which defined the json file. From this page we can find basically the principle of swagger:

  1. swagger rely json document based openapi specification, which defines the interface scheme.
  2. After the page loads, the scheme will get the specified interface, and then generate the interface page.
  3. Click execution, sends ajax request, then the results will be presented on the screen, in order to achieve through a browser interface testing.

Simple terms, swagger interface testing is to achieve a pure front-end, back-end support is not required. It is an online version of the postman, in fact, postman also supports openapi specification, by the import scheme, can also achieve the same functionality. However, the postman and compared, swagger has the following advantages:

  1. No local client
  2. And application integration may not need to manually import the interface definition
  3. ajax request sent by the browser, the user can often be automatically basis of identity, access control test with an interface very easy to use.

In the .net core, to swaggerui and site integration, you need the following steps:

  1. According ApiExplore interface documentation generated content
  2. Registration routing, provides the interface documentation Download
  3. The swaggerui page integrated into your site
  4. The routing path is set to swagger page

Simple terms on a two-step, provide interface documentation download url and integration swaggerui. Current .net core've got some open source implementation, such as: swashbuckle and nswag . For most scenarios, the direct use of them is very convenient.

However, sometimes we need some advanced features, such as distributed services necessary to provide a centralized api page, or a page needs some customization (such as grouping, access control, style adjustment). Although these libraries also provide some support, but often not flexible enough. A simple solution is: only use these libraries to generate swagger interface documentation swagger.json, their own custom UI in the official static pages based on this to be more flexible.

Guess you like

Origin www.cnblogs.com/TianFang/p/12596074.html