OpenAPITools / OpenAPITools/openapi-generator

Requesting new configOption for JavaJAXRSS to generate or not both RestApplication.java and RestResourceRoot.java

Open
#20,287 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

I'm working on a project where i need to generate several swagger specs through different config :

<executions>
  <execution>
      <id>ex1</id>
      <goals>
          <goal>generate</goal>
      </goals>
      <configuration>
          <inputSpec>
              ${project.basedir}/spec1.yaml
          </inputSpec>
          <modelPackage>path1.api</modelPackage>
          <apiPackage>path1.model</apiPackage>
      </configuration>
  </execution>
<execution>
      <id>ex2</id>
      <goals>
          <goal>generate</goal>
      </goals>
      <configuration>
          <inputSpec>
              ${project.basedir}/spec2.yaml
          </inputSpec>
          <modelPackage>path2.api</modelPackage>
          <apiPackage>path2.model</apiPackage>
      </configuration>
  </execution>

Problem is that both execution generates RestApplication.java and RestResourceRoot.java (which are not useful to my project...) , and having multiple of those give me the following error at build :

java.lang.RuntimeException:
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.resteasy.reactive.common.deployment.ResteasyReactiveCommonProcessor#handleApplication threw an exception: java.lang.RuntimeException: More than one Application class: [path1.RestApplication, path2.RestApplication]

Problem exists since https://github.com/OpenAPITools/openapi-generator/issues/17645

Describe the solution you'd like

Please introduce an new configOption (true by default to remain backward compatible) to enable generation of those files or not here :

https://github.com/OpenAPITools/openapi-generator/blame/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java#L178
https://github.com/OpenAPITools/openapi-generator/blame/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java#L187

Describe alternatives you've considered

Currently, as work-around, i have to delete the generated files after it has been generated
Example for people having the same issue :

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.7</version>
	<executions>
		<execution>
			<phase>generate-sources</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<tasks>
					<delete>
						<fileset dir="${project.build.directory}\path1\" includes="RestApplication.java"/>
						<fileset dir="${project.build.directory}\path1\" includes="RestResourceRoot.java"/>
						<fileset dir="${project.build.directory}\path2\" includes="RestApplication.java"/>
						<fileset dir="${project.build.directory}\path2\" includes="RestResourceRoot.java"/>
					</delete>
				</tasks>
			</configuration>
		</execution>
	</executions>
</plugin>

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 in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java at the referenced lines, where RestApplication.java and RestResourceRoot.java generation is configured. Add an option that controls both files while preserving the default behavior, then verify that separate Maven executions can disable their generation without producing those files.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.