简体   繁体   English

swagger-codegen-maven-plugin 在生成 API class 时忽略我为 ZonedDateTime 设置的导入映射

[英]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.

相关问题 删除 swagger-codegen-maven-plugin api class 中的 ResponseEntity - Remove ResponseEntity in swagger-codegen-maven-plugin api class 如何使用swagger-codegen-maven-plugin生成maven存储库就绪库? - How can I generate a maven repository-ready library with swagger-codegen-maven-plugin? swagger-codegen-maven-plugin中使用什么invokerPackage? - What invokerPackage is used for in swagger-codegen-maven-plugin? 带有 springdoc-openapi-ui 的 swagger-codegen-maven-plugin - swagger-codegen-maven-plugin with springdoc-openapi-ui 如何使用 springdoc-openapi-maven-plugin 和 swagger-codegen-maven-plugin 生成客户端代码? - How to generate client code using springdoc-openapi-maven-plugin and swagger-codegen-maven-plugin? “swagger-codegen-maven-plugin:3.0.0 或其依赖项之一无法解析” - "swagger-codegen-maven-plugin:3.0.0 or one of its dependencies could not be resolved" 使用 swagger-codegen maven 插件生成代码时删除默认实现 - remove default implementation while generating code using swagger-codegen maven plugin Swagger Codegen,Maven插件:限制服务器生成 - Swagger Codegen, Maven Plugin: Restrict Server Generation jaxb2-maven-plugin 在生成 xsd 时忽略命名空间 - 两个类具有相同的 XML 类型 - jaxb2-maven-plugin ignores namespace when generating xsd - Two classes have the same XML type 您如何让Maven swagger Codegen插件使用继承生成Java类? - How do you have the maven swagger codegen plugin generate Java classes using inheritance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM