Show Swagger validation information

2019-03-01 08:55发布

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?

标签: rest api swagger
2条回答
2楼-- · 2019-03-01 09:17

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

查看更多
Deceive 欺骗
3楼-- · 2019-03-01 09:21

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.

查看更多
登录 后发表回答