Search code examples
springdoc-openapi-uispringdoc-ui

Springdoc openapi 3 @Schema example ignored


@Schema Example is ignored by springdoc Openapi on one class property, but working on other property in the same class. Added

@Schema(type = "integer", format = "int64", example = "1560868939063") private Instant date; on a field of a Class. Accessing the /v3/api-docs endpoint i can see that the example was completely ignored, it shows:

"MyClass":{"type":"object","properties":{"date":{"type":"integer","format":"int64"},...

EDIT: It seems that it is ignored because the type of the Field is of java.time.Instant, meaning the actual java class property type, not the "type" property in the @Schema. On a Field of type for example String, it works and shows the example.

using spring-boot 2.5:

api "org.springdoc:springdoc-openapi-ui:1.6.4"
api "org.springdoc:springdoc-openapi-data-rest:1.6.4"
api "org.springdoc:springdoc-openapi-security:1.6.4"

Solution

  • I have a configuration in my base configuration project, which seems to override the Schema. Although i don't think that this is how it is supposed to work, but if i delete this, it works.

    SpringDocUtils.getConfig().replaceWithClass(Instant.class, Long.class);