Describe a multiple range parameter with Swagger

谁都会走 提交于 2020-03-23 12:37:08

问题


I want to describe in Swagger 2.0 a parameter defined as follows :

  • The parameter takes a valid value in the intervals : -20 < parameter < -10 or 0 < parameter < 30

  • The parameter is invalid if : -10 ≤ parameter ≤ 0

This means that it has two valid intervals and thus two max and mins values to define. Does Swagger specification support that kind of definitions?


回答1:


This cannot be described in OpenAPI/Swagger 2.0, but can be described in OpenAPI 3.0 using oneOf.

# openapi: 3.0.0

type: integer
oneOf:
  - minimum: -20
    maximum: -10
    exclusiveMinimum: true
    exclusiveMaximum: true
  - minimum: 0
    maximum: 30
    exclusiveMinimum: true
    exclusiveMaximum: true


来源:https://stackoverflow.com/questions/58874658/describe-a-multiple-range-parameter-with-swagger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!