yakovburtsev
4 years agoOccasional Visitor
How do I properly define an example for a nullable property in OpenAPI 3?
I am using OpenAPI and openapi-generator-maven-plugin with Spring Boot. I'm trying to create an example object in my response. I've followed the suggestions of several different web pages, especially this one:
https://swagger.io/docs/specification/adding-examples/
But no matter what I try, I can't get the example data to show up correctly. Here the object that should be in a request:
Period:
type: object
required:
- startDate
- endDate
properties:
startDate:
type: string
format: date
nullable: true
example: "2021-01-01"
endDate:
type: string
format: date
nullable: true
example: "2030-01-01"
CreateInstancesRequest:
type: object
required:
- id
properties:
id:
$ref: '#/components/schemas/Id'
period:
allOf:
- $ref: '#/components/schemas/Period'
But I get not what I want:
I expect something like this:
{
"id": "some-id",
"period": {
"endDate": "2020-01-01",
"startDate": "2022-01-01"
}
}
But maybe I am wrong because generated java code for the Period class:
I think present property from actual example came from org.openapitools.jackson.nullable.JsonNullable class.
Can you help me, please?