Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger-maven-plugin-jakarta is always using the resourceClasses from the first execution #4647

Open
ahoehma opened this issue Apr 7, 2024 · 1 comment

Comments

@ahoehma
Copy link

ahoehma commented Apr 7, 2024

I define multiple executions for swagger-maven-plugin-jakarta and it seems that the resourceClasses from the first execution is re-used in all following executions.

All the generated outputs have the same content :-)

<properties>
    <api.version>1.20</api.version>
    <api.version.new>${api.version}</api.version.new>
    <cc.openapi.configuration.new>cc-${api.version.new}-configuration</cc.openapi.configuration.new>
    <cc.openapi.history.new>cc-${api.version.new}-history</cc.openapi.history.new>
    <cc.openapi.history-analytics.new>cc-${api.version.new}-history-analytics</cc.openapi.history-analytics.new>
    <cc.openapi.products.new>cc-${api.version.new}-products</cc.openapi.products.new>
    <cc.openapi.brain.new>cc-${api.version.new}-brain</cc.openapi.brain.new>
    <cc.openapi.creation-cache.new>cc-${api.version.new}-creation-cache</cc.openapi.creation-cache.new>
    <cc.openapi.settings.new>cc-${api.version.new}-settings</cc.openapi.settings.new>
    <cc.openapi.vt.new>cc-${api.version.new}-vt</cc.openapi.vt.new>
  </properties>

<profiles>
    <profile>
      <id>generate-api</id>
      <build>
        <plugins>
          <plugin>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-maven-plugin-jakarta</artifactId>
            <version>2.2.21</version>
            <configuration>
              <outputFormat>JSONANDYAML</outputFormat>
              <encoding>UTF-8</encoding>
              <sortOutput>true</sortOutput>
              <prettyPrint>true</prettyPrint>
              <readAllResources>false</readAllResources>
              <!-- see src/main/resources/META-INF/cc-api-config.yaml - filtered by maven during build with some values from cc top-level pom!-->
              <openapiFilePath>${project.build.outputDirectory}/META-INF/cc-api-config.yaml</openapiFilePath>
              <openapi31>false</openapi31>
            </configuration>
            <executions>
              <execution>
                <id>generate-api-cc-configuration</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.configuration.new}</outputFileName>
<!------------------------ this one is used for all following executions ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.service.configuration.ConfigurationController</resourceClasses>
                </configuration>
              </execution>
              <execution>
                <id>generate-api-cc-configuration-history</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.history.new}</outputFileName>
<!------------------------ this one is completely ignored ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.api.HistoryControllerApi</resourceClasses>
                </configuration>
              </execution>
              <execution>
                <id>generate-api-cc-configuration-history-analytics</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.history-analytics.new}</outputFileName>
<!------------------------ this one is completely ignored ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.service.history.HistoryAnalyticsController</resourceClasses>
                </configuration>
              </execution>
              <execution>
                <id>generate-api-cc-configuration-products</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.products.new}</outputFileName>
<!------------------------ this one is completely ignored ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.service.products.ProductsController</resourceClasses>
                </configuration>
              </execution>
              <execution>
                <id>generate-api-cc-configuration-brain</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.brain.new}</outputFileName>
<!------------------------ this one is completely ignored ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.api.BrainControllerApi</resourceClasses>
                </configuration>
              </execution>
              <execution>
                <id>generate-api-cc-configuration-creation-cache</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.creation-cache.new}</outputFileName>
<!------------------------ this one is completely ignored ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.service.cache.CreationCacheController</resourceClasses>
                </configuration>
              </execution>
              <execution>
                <id>generate-api-cc-configuration-vt</id>
                <goals>
                  <goal>resolve</goal>
                </goals>
                <configuration>
                  <outputPath>${project.basedir}/target/openapi-generated/v${api.version.new}/</outputPath>
                  <outputFileName>${cc.openapi.vt.new}</outputFileName>
<!------------------------ this one is completely ignored ?! ------------------------------------->
                  <resourceClasses>com.siemens.spice.cc.rest.service.vt.VariantTableController</resourceClasses>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-configuration.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-configuration.yaml
[INFO]
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration-history) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-history.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-history.yaml
[INFO]
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration-history-analytics) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-history-analytics.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-history-analytics.yaml
[INFO]
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration-products) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-products.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-products.yaml
[INFO]
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration-brain) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-brain.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-brain.yaml
[INFO]
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration-creation-cache) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-creation-cache.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-creation-cache.yaml
[INFO]
[INFO] --- swagger:2.2.21:resolve (generate-api-cc-configuration-vt) @ rest-service ---
[INFO] Resolving OpenAPI specification..
[INFO] JSON output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-vt.json
[INFO] YAML output: D:\Dev\git\coc\spice-configuration-cluster\rest-service\target\openapi-generated\v1.20\cc-1.20-vt.yaml

May there is a wrong data-handling in the plugin, i,e static variable or something?!

@ahoehma
Copy link
Author

ahoehma commented Apr 8, 2024

I found the "problem" :) It has nothing todo with the maven plugin itself and how it read/merge the config. This is all fine. Its all about the "context-id" :-) (Singletons are ugly)

This line in io.swagger.v3.oas.integration.GenericOpenApiContextBuilder is causing the trouble:

OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId);

If no context-id is given then the maven plugin is using ${project.artifactId} as default. So also in case multiple executions with different settings are expected which results at end in using the same open-api-context again and again.

So its not really a bug or something ... its more a missing hint in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant