Show Swagger validation information

2019-03-01 09:00发布

问题:

Swagger UI does not show request parameter's validation information. I want to show parameter's min value, max value, format, pattern(regex). Does anyone know the way how I express the parameter's validation information on Swagger UI?

回答1:

Assuming you use Swagger UI 3.x (the latest version), add showCommonExtensions: true to the Swagger UI initialization code in your index.html file:

const ui = SwaggerUIBundle({
  "dom_id": "#swagger-ui",
  url: "https://petstore.swagger.io/v2/swagger.json",
  showExtensions: true,    // <-----
  ...

Learn more about Swagger UI configuration parameters.



回答2:

By using openapi 3.0.0 I got a UI with validation information like that displayed in http://editor.swagger.io/. Conversion from openapi 2 to openapi 3 could be done at the following URL. https://mermade.org.uk/openapi-converter



标签: rest api swagger