本文介绍了OpenAPI 生成器中的错误?日期数据类型示例值的格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 4.2.3 版本的 openapi-generator-maven-plugin.

我的配置如下:

 <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><!-- 传递任何必要的配置选项--><configOptions><java8>真</java8><skipDefaultInterface>true</skipDefaultInterface><dateLibrary>java8</dateLibrary><interfaceOnly>true</interfaceOnly><swaggerDocketConfig>false</swaggerDocketConfig><hateoas>true</hateoas></configOptions>

在 ma yaml 中,我使用示例参数定义了我的属性:

 myDate:类型:字符串"格式:日期"描述:我的约会"示例:2012-10-11"

但是插件忽略了示例:在我生成的代码中,我有:

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

我想要一个像我的 yaml 文件中的例子.YYYY-MM-DD 格式.

我正在使用:

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

解决方案

几个小时后我找到了解决方案:

我的日期:类型:日期"格式:yyyy-mm-dd"描述:我的约会"例如:2012-10-11"

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:

解决方案

After few hours I found solution:

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

这篇关于OpenAPI 生成器中的错误?日期数据类型示例值的格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 11:55