【问题标题】:Generate files in different folders using Open API generator使用 Open API 生成器在不同文件夹中生成文件
【发布时间】:2022-01-13 17:52:44
【问题描述】:

我正在使用 openapi-generator 从 JsonSchema 生成 POJO。 在我的 pom.xml 中,我指定了

<output>${project.build.directory}/generated-sources/openapi</output><modelPackage>com.test.generated.model</modelPackage>

这会生成所有文件:

generated-sources/openapi/src/main/java/com.test.generated.model

我有基于不同架构的冲突类名,这会导致错误。

有没有办法在单独的文件夹中为每个架构单独自动生成?

【问题讨论】:

    标签: java openapi openapi-generator


    【解决方案1】:

    我认为您将多个 openapi 模式生成到一个包中。为每个开放模式保持多次执行(通过提供不同的包)可以解决它。这是我用于此类目的的基本方式:

    <plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>4.3.1</version>
    <executions>
        <execution>
            <id>gen1</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/../openapi/openapi-spec1.yml</inputSpec>
                <generatorName>spring</generatorName>
                <library>spring-boot</library>
                <apiPackage>${project.groupId}.spec1.api</apiPackage>
                <modelPackage>${project.groupId}.spec1.api.model</modelPackage>
                <configOptions>
                    <skipDefaultInterface>true</skipDefaultInterface>
                    <dateLibrary>java8</dateLibrary>
                    <interfaceOnly>true</interfaceOnly>
                    <sourceFolder>src/gen/java/main</sourceFolder>
                </configOptions>
                <configHelp>false</configHelp>
            </configuration>
        </execution>
        <execution>
            <id>gen2</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/../openapi/openapi-spec2.yml</inputSpec>
                <generatorName>spring</generatorName>
                <library>spring-boot</library>
                <apiPackage>${project.groupId}.spec2.api</apiPackage>
                <modelPackage>${project.groupId}.spec2.api.model</modelPackage>
                <configOptions>
                    <skipDefaultInterface>true</skipDefaultInterface>
                    <dateLibrary>java8</dateLibrary>
                    <interfaceOnly>true</interfaceOnly>
                    <sourceFolder>src/gen/java/main</sourceFolder>
                </configOptions>
                <configHelp>false</configHelp>
            </configuration>
        </execution>
        <execution>
            <id>gen3</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/../openapi/openapi-spec3.yml</inputSpec>
                <generatorName>spring</generatorName>
                <library>spring-boot</library>
                <apiPackage>${project.groupId}.spec3.api</apiPackage>
                <modelPackage>${project.groupId}.spec3.api.model</modelPackage>
                <configOptions>
                    <skipDefaultInterface>true</skipDefaultInterface>
                    <dateLibrary>java8</dateLibrary>
                    <interfaceOnly>true</interfaceOnly>
                    <sourceFolder>src/gen/java/main</sourceFolder>
                </configOptions>
                <configHelp>false</configHelp>
            </configuration>
        </execution>                           
    </executions>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-24
      相关资源
      最近更新 更多