OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] openapi-generator maven plugin erases project pom.xml and replaces with pom for ApiClient

Open
#20,528 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When using the openapi-generator-maven-plugin, the main pom.xml file is overwritten and the project is unable to be built again. The issue appears in version 5.0.0 of the maven plugin and onwards.

Execution spec

Below is the configuration used. The only thing I have changed is to add the useJakartaEe attribute.

<plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>7.10.0</version>
        <executions>
          <execution>
            <id>example-api</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>
                src/main/resources/ExampleService-swagger.yaml</inputSpec>
              <generatorName>java</generatorName>
              <output>${project.basedir}</output>
              <modelPackage>
                com.pomoverwriter.reproducer.components</modelPackage>
              <generateApis>true</generateApis>
              <generateApiTests>false</generateApiTests>
              <generateApiDocumentation>true</generateApiDocumentation>
              <generateModelTests>false</generateModelTests>
              <generateSupportingFiles>true</generateSupportingFiles>
              <environmentVariables>
                <hideGenerationTimestamp/>
              </environmentVariables>
              <validateSpec>false</validateSpec>
              <typeMappings>
                <typeMapping>OffsetDateTime=String</typeMapping>
              </typeMappings>
              <configOptions>
                <sourceFolder>src/main/generated</sourceFolder>
                <serializableModel>true</serializableModel>
                <useBeanValidation>true</useBeanValidation>
                <dateLibrary>java8</dateLibrary>
                <library>resteasy</library>
                <validateSpec>false</validateSpec>
                <useJakartaEe>true</useJakartaEe>
              </configOptions>
            </configuration>
          </execution>
		</executions>
      </plugin>

If I add the below to the <execution> definition, it does not overwrite the pom.xml:

<globalProperties>
  <apis>false</apis>
  <apiTests>false</apiTests>
  <modelDocs>false</modelDocs>
  <modelTests>false</modelTests>
  <supportingFiles>false</supportingFiles>
</globalProperties>
Generation Details

I have created a reproducer here: https://github.com/bmulkinfor/openapi-pomoverwrite-reproducer

Steps to reproduce

Clone the reproducer linked above, and just run mvn clean package

Once pom is overwritten, copy pom.xml.bkp to pom.xml

Extra Comment

I am not very experienced with this plugin; I usually use the swagger codegen maven plugin but never had issues with main project build file being overwritten. I'm not sure why I should have to add any configuration to the plugin to ensure that the pom.xml is not overwritten.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproducer's pom.xml and run mvn clean package using the shown openapi-generator-maven-plugin configuration. Compare the resulting pom.xml with pom.xml.bkp and trace the plugin's generation behavior; done means the main project pom.xml remains intact while the requested generated files are produced.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.