2

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?

Helen
  • 87,344
  • 17
  • 243
  • 314
Sara Sara
  • 57
  • 1
  • 8
  • Related: [How does one indicate that a number is prohibited for use in Swagger documentation?](https://stackoverflow.com/q/60657280/113116) – Helen Mar 12 '20 at 16:02

1 Answers1

3

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

OpenAPI 3.0

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

OpenAPI 3.1

type: integer
oneOf:
  - exclusiveMinimum: -20
    exclusiveMaximum: -10
  - exclusiveMinimum: 0
    exclusiveMaximum: 30

exclusiveM* keywords were changed from boolean to numbers in JSON Schema Draft 6. OAS 3.1 uses JSON Schema 2020-12 by default.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thank you .. That was very useful .. Do you know how can this be translated in Spring Annotations? – Sara Sara Nov 18 '19 at 09:14
  • @SaraSara I don't know, sorry. Feel free to [ask a new question](/questions/ask?tags=java+spring+swagger) about this. – Helen Nov 19 '19 at 12:28