swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

OpenApi not picking up 'example' from @Schema

Open dbnex14 opened this issue 3 years ago • 1 comments

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: image

Here is how it shows in my model: image

And here is how Example value of my controller looks: image

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: image

, then my schema model shows it image

, and also example in controller shows it as 19680210: image

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

dbnex14 avatar Jun 28 '22 20:06 dbnex14