[英]swagger-codegen-maven-plugin ignores the importmapping i have set for ZonedDateTime when generating an API class
I am trying to generate an API class from a yaml file using ZonedDateTime as the class for a date.我正在尝试从 yaml 文件生成 API class 使用 ZonedDateTime 作为日期的 ZA2F2ED4F8EBC2CBB1DZC21。 When i do this i can successfully change the generated class OffsetDateTime to ZonedDateTime in the configuration, but the correct import statement is not generated, which causes an error.当我这样做时,我可以在配置中成功地将生成的 class OffsetDateTime 更改为 ZonedDateTime,但是没有生成正确的导入语句,这会导致错误。 It only imports import java.time.OffsetDateTime;
它只导入import java.time.OffsetDateTime;
. . Does anybody have an idea to what I can try so it generates the correct import?有人知道我可以尝试什么以生成正确的导入吗?
This is my latest attempt to configure it in the pom, and I am using the swagger-codegen-maven-plugin, version 3.0.20, from io.swagger.codegen.v3.这是我在 pom 中配置它的最新尝试,我正在使用来自 io.swagger.codegen.v3 的 swagger-codegen-maven-plugin,版本 3.0.20。
<configuration>
<additionalProperties>
<additionalProperty>ignoreImportMappings=false</additionalProperty>
</additionalProperties>
<generateSupportingFiles>false</generateSupportingFiles>
<inputSpec>${project.basedir}/src/main/resources/api/api.yaml</inputSpec>
<modelPackage>api.domene</modelPackage>
<language>spring</language>
<generateModels>true</generateModels>
<generateApis>true</generateApis>
<generateApiTests>false</generateApiTests>
<configOptions>
<library>spring-boot</library>
<interfaceOnly>true</interfaceOnly>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<useTags>true</useTags>
<java8>true</java8>
<serializableModel>true</serializableModel>
<dateLibrary>java8</dateLibrary>
</configOptions>
<typeMappings>OffsetDateTime=ZonedDateTime</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.ZonedDateTime</importMapping>
</importMappings>
</configuration>
The importMappings and importMapping tags do not work, you are right. importMappings 和 importMapping 标签不起作用,你是对的。 But there is a workaround;但是有一个解决方法;
...
</configOptions>
<typeMappings>
<typeMapping>OffsetDateTime=java.time.ZonedDateTime</typeMapping>
</typeMappings>
</configuration>
That way, in the generated sources, even though the import section contain "import java.time.OffsetDateTime;", the generated method parameters and variables will be defined as "java.time.ZonedDateTime" so you can use correct date functions in your code.这样,在生成的源代码中,即使导入部分包含“import java.time.OffsetDateTime;”,生成的方法参数和变量将被定义为“java.time.ZonedDateTime”,因此您可以在您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.