Closed davidkeaveny closed 3 months ago
@davidkeaveny I tried it out and there are better solutions than the ones you suggested. I worked from the error message stating that nullable cannot be used without a type.
Here are my solutions:
Move nullable to the address (which is possible not what you want if you reuse it somewhere else):
components:
schemas:
address:
type: object
description: A geographical address.
properties:
....
nullable: true
createPersonalDetails:
type: object
...
properties:
homeAddress:
description: The person's home address.
allOf:
- $ref: '#/components/schemas/address'
emailAddress:
type: string
description: The person's email address.
format: email
nullable: true
Don't use allOff, but instead use anyOf for the homeAddress:
homeAddress:
description: The person's home address.
anyOf:
- $ref: '#/components/schemas/address'
- type: object
nullable: true
I hope this helps to solve your problem.
When using an OpenAPI specification where a property is defined using a
$ref
and that property is marked as nullable, the linter is returning an error when an example is given.The following OAS3.0 specification illustrates the problem:
This returns the following error:
I will get the same error if I:
nullable
to falsehomeAddress
from the exampleI can only clear the error if I either remove the example altogether, or if I change the definition to:
but that means the field is no longer nullable, and I have lost the description - neither of these are good solutions.
Any thoughts?