K2mil J33
K2mil J33

Reputation: 165

Bug in OpenAPI generator? Wrong format for the example value of date datatype

I'm using a openapi-generator-maven-plugin with 4.2.3 version.

My configuration looks like this:

                       <typeMappings>
                            <typeMapping>OffsetDate=LocalDate</typeMapping>
                            <typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
                        </typeMappings>
                        <importMappings>
                            <importMapping>java.time.OffsetDate=java.time.LocalDate</importMapping>
                            <importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
                        </importMappings>
                        <!-- pass any necessary config options -->
                        <configOptions>
                            <java8>true</java8>
                            <skipDefaultInterface>true</skipDefaultInterface>
                            <dateLibrary>java8</dateLibrary>
                            <interfaceOnly>true</interfaceOnly>
                            <swaggerDocketConfig>false</swaggerDocketConfig>
                            <hateoas>true</hateoas>
                        </configOptions>

In ma yaml I defined my property with example parameter:

 myDate:
   type: "string"
   format: "date"
   description: "My date"
   example: "2012-10-11"

But example is ignored by plugin: In my generated code I have:

  @ApiModelProperty(example = "Thu Oct 11 02:00:00 CEST 2012", required = true, value = "My date")

I would like have a example like in my yaml file. In YYYY-MM-DD format.

I'm using:

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-spring-webmvc</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.openapitools</groupId>
        <artifactId>jackson-databind-nullable</artifactId>
        <version>0.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
        <version>2.10.2</version>
    </dependency>

Upvotes: 2

Views: 10663

Answers (2)

K2mil J33
K2mil J33

Reputation: 165

After a few hours I found a solution:

 myDate:
   type: "date"
   format: "yyyy-mm-dd"
   description: "My date"
   example: "2012-10-11"

Upvotes: 0

Igor Nosovskyi
Igor Nosovskyi

Reputation: 124

For me helps type 'string' with the format that I need.

start_at:
          type: string
          format: 'yyyy-mm-dd'

Upvotes: 0

Related Questions