Title: Unable to Display Example Value for LocalDateTime Field in Spring Boot OpenAPI Documentation

32 Views Asked by At

I am using Spring Boot 3 with the following OpenApi dependencies:

<version.springdoc.openapi>2.1.0</version.springdoc.openapi>

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
  <version>${version.springdoc.openapi}</version>
</dependency>

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
  <version>${version.springdoc.openapi}</version>
</dependency>

I am working on a Spring Boot application using version 2.1.0 of the Springdoc OpenAPI library. In my project, I have a model class with a field of type LocalDateTime, and I'm trying to specify an example value for this field using the @Schema annotation. However, despite setting the example value in the annotation, the generated OpenAPI documentation still displays the default string($date-time) instead of the provided example.

Here's an example of how I'm using the @Schema annotation in my model class:

import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

public class YourModel {

    @Schema(description = "Event date and time", format = "date-time", example = "2022-12-31T23:59:59")
    private LocalDateTime creationDateTime;

    // Getters and setters
}

I've verified that my dependencies are correctly configured, and the Springdoc OpenAPI library version I'm using should support specifying example values for schema properties.

Any suggestions on how to resolve this issue and get the example value to display correctly in the generated OpenAPI documentation would be greatly appreciated. Thank you.

1

There are 1 best solutions below

0
Yasar On

You can use "type" definition of @Schema to display custom format as string:

@Schema(description = "Event date and time", type = "string", example = "2022-12-31T23:59:59")
private LocalDateTime creationDateTime;