打开 API Maven 插件 - 仅生成特定的 API 模型 类

Open API Maven Plugin - Generate only specifc API model classes

我正在通过 Open API Maven 插件生成模型 类,我需要在我的业务逻辑中使用它。 api 由其他团队生成并提供给我们。它有很多模型 类 规范,但我只需要从 api.yaml 模板

生成 3 个模型 类

如何实现?

插件配置

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-java-client</id>
            <configuration>
                <inputSpec>
                    ${project.build.directory}/../../../../../../../../../component/service/app/src/main/resources/api/v1/api-v1.yaml
                </inputSpec>
                **<modelPackage>com.example.editing.model</modelPackage>**
                <generateSupportingFiles>false</generateSupportingFiles>
                <generateApis>false</generateApis>
                <generateApiTests>false</generateApiTests>
                <generateModelTests>false</generateModelTests>
            </configuration>
        </execution>
    </executions>
</plugin>

根据 github readme of the openapi-generator-maven-plugin,有一个名为 modelsToGenerate 的配置选项,它完全符合您的要求:

A comma separated list of models to generate. All models is the default.