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

烈酒焚心 提交于 2021-01-29 21:24:17

问题


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>

回答1:


After few hours I found solution:

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



来源:https://stackoverflow.com/questions/61082113/bug-in-openapi-generator-wrong-format-for-the-example-value-of-date-datatype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!