I am trying to write Swagger documentation where two out of the five fields are required in a POST request. I've read a few options on how to do this, but can't seem to find a definitive answer.
Option 1:
/my-endpoint:
post:
x-swagger-router-controller: example.spec
operationId: example_operationId
parameters:
- in: body
name: recovery_data
description: TODO
schema:
$ref: '#/definitions/RecoveryData'
required: true
responses:
200:
description: TODO
schema:
$ref: '#/definitions/OkResponse'
RecoveryData:
type: object
properties:
required_field_1:
description: TODO
type: array
required: true
required_field_2:
description: TODO
type: string
required: true
optional_field_1:
description: TODO
type: boolean
required: false
optional_field_2:
description: TODO
type: boolean
required: false
optional_field_3:
description: TODO
type: boolean
required: false
optional_field_4:
description: TODO
type: string
required: false
Option 2:
/my-endpoint:
post:
x-swagger-router-controller: example.spec
operationId: example_operationId
parameters:
- in: body
name: recovery_data
description: TODO
schema:
$ref: '#/definitions/RecoveryData'
responses:
200:
description: TODO
schema:
$ref: '#/definitions/OkResponse'
RecoveryData:
type: object
properties:
required_field_1:
description: TODO
type: array
required: true
required_field_2:
description: TODO
type: string
required: true
optional_field_1:
description: TODO
type: boolean
optional_field_2:
description: TODO
type: boolean
optional_field_3:
description: TODO
type: boolean
optional_field_4:
description: TODO
type: string
In Option 1 I specify required: true
in the parameters: part of the request, then write out which params are actually required or not in the schema. In option 2, I don't have required: true
in the parameters, and then only write which fields are required.
Does anyone know which way is right?