javamodelmaven-pluginopenapigenerated-code

Open API Maven Plugin - Generate only specifc API model classes


I am working on generation of model classes by Open API Maven plugin which I need to use in my business logic. The api is generated by other team and given to us. It has lot of model classes specification but I need only generation of 3 model classes from the api.yaml template

How this can be achieved?

The plugin configuration

<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>

Solution

  • According to the github readme of the openapi-generator-maven-plugin, there is a configuration option called modelsToGenerate which does exactly what you want:

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