swagger-core
swagger-core copied to clipboard
OpenApi not picking up 'example' from @Schema
In my request model, I have a field like
@NotNull
@Schema(description = "blahblah", example = "19680228", type = "Date", format = "String", pattern = "([0-9]{4})(?:[0-9]{2})([0-9]{2})", required = true, nullable = false)
@JsonDeserialize(using = CustomDateDeserializer.class)
private OffsetDateTime birthDate;
As you can see, I have example = "19680228" in @Schema.
When I go to https://editor.swagger.io/ and paste my .yaml file into it, I would expect that it would pick the example up and show the birthDate in example section of my endpoint and in my model schema as 19680228. I would else expect that example was generated in yaml when I hit the /api-docs.yaml endpoint but it is not:

Here is how it shows in my model:

And here is how Example value of my controller looks:

As you can see, the format is still getting the format for OffsetDateTime and there is no example at all.
However, if I modify yaml in https://editor.swagger.io/ and add example as below:

, then my schema model shows it

, and also example in controller shows it as 19680210:

So, it looks like OpenApi is not processing @Schema properly.