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

[BUG] [Java] Generated methods have a "_<number>" suffix #19865

Closed
ahoehma opened this issue Oct 14, 2024 · 6 comments · Fixed by #19913
Closed

[BUG] [Java] Generated methods have a "_<number>" suffix #19865

ahoehma opened this issue Oct 14, 2024 · 6 comments · Fixed by #19913

Comments

@ahoehma
Copy link

ahoehma commented Oct 14, 2024

Description

Since version 7.9.0 my generated java-client looks different. Almost all methods got an additional "_NN" on there names which is breaking my surrounding java code.

openapi-generator version

7.9.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "paths": {
     "/api/v1/brain/product/localizations/{productId}/{version}": {
      "post": {
        "tags": [
          "read",
          "service",
          "v1.24"
        ],
        "summary": "Get localization data for a product. This was introduced in 2024.15.0 with api 1.24.",
        "operationId": "getProductLocalizations",
        "parameters": [
          {
            "name": "productId",
            "in": "path",
            "description": "Provide the id of the product.",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "1LE1X"
          },
          {
            "name": "version",
            "in": "path",
            "description": "Provide the version of the product. Could be 'LATEST' to retrieve the newest version.",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "LATEST"
          }
        ],
        "requestBody": {
          "description": "Required payload for the request.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GetProductLocalizationsPayload"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetProductLocalizationsResult"
                }
              }
            }
          }
      }
    }
}
...

I can't post the whole definition because of closed source ... but the interesting part is here I hope. It's all about the "operationId": "getProductLocalizations" ... and all the "operationId's" are unique in the openapi.json.

Generation Details
<plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>7.9.0</version>
        <configuration>
          <!-- https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md -->
          <generatorName>java</generatorName>
          <addCompileSourceRoot>true</addCompileSourceRoot>
          <generateModelTests>false</generateModelTests>
          <skipOverwrite>false</skipOverwrite>
          <indentSize>2</indentSize>
          <lineLength>200</lineLength>
          <verbose>false</verbose>
          <skipIfSpecIsUnchanged>false</skipIfSpecIsUnchanged>
          <configOptions>
            <additionalModelTypeAnnotations><![CDATA[ @SuppressWarnings("all") ]]></additionalModelTypeAnnotations>
            <enumUnknownDefaultCase>true</enumUnknownDefaultCase>
            <library>resttemplate</library>
            <java8>true</java8>
            <dateLibrary>java8</dateLibrary>
            <failOnUnknownProperties>false</failOnUnknownProperties>
            <sortModelPropertiesByRequiredFlag>false</sortModelPropertiesByRequiredFlag>
            <sortParamsByRequiredFlag>false</sortParamsByRequiredFlag>
          </configOptions>
        </configuration>
<executions>
<execution>
            <id>generate-apiclient-cc-configuration-brain</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${openapi.input.cerebellum}</inputSpec> <!-- kleinhirn -->
              <output>${project.build.directory}/generated-sources/cc-api-cerebellum</output>
              <apiPackage>com.foo.spice.cc.client.brain.api</apiPackage>
              <modelPackage>com.foo.spice.cc.client.brain.model</modelPackage>
              <invokerPackage>com.foo.spice.cc.client.brain.handler</invokerPackage>
            </configuration>
          </execution>
<executions>
</plugin>

The generated code looks like this:

/**
     * Get localization data for a product. This was introduced in 2024.15.0 with api 1.24.
     * 
     * <p><b>200</b> - OK
     * @param productId Provide the id of the product. (required)
     * @param version Provide the version of the product. Could be &#39;LATEST&#39; to retrieve the newest version. (required)
     * @param getProductLocalizationsPayload Required payload for the request. (required)
     * @return GetProductLocalizationsResult
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public GetProductLocalizationsResult getProductLocalizations_0(String productId, String version, GetProductLocalizationsPayload getProductLocalizationsPayload) throws RestClientException {
        return getProductLocalizations_0WithHttpInfo(productId, version, getProductLocalizationsPayload).getBody();
    }

How to disable this additional suffixes? And why there are even there ? :-)

Kind regards
Andreas

@ahoehma
Copy link
Author

ahoehma commented Oct 14, 2024

I enabled verbose logging and I found something like this (here another method but same effect):

"operationIdOriginal" : "removeServiceProduct",
"operationIdLowerCase" : "removeserviceproduct_0",
"operationIdCamelCase" : "RemoveServiceProduct0",
"operationIdSnakeCase" : "remove_service_product_0",

@Kuba15
Copy link

Kuba15 commented Oct 17, 2024

Hello,
I have noticed something similar with the "kotlin-spring" generator since 7.9.0, but in the following case:
The "_0" is applied on function that have in the OpenAPI definition file the same "operationId", event with different tags (leading them to be generated in different Kotlin interfaces).
During the OpenAPI code generation (via gradle plugin), we can see this message:
generated unique operationId '<operationId>_0'

@ahoehma do you have in your OpenAPI definition file another operationId "getProductLocalizations"?

@ahoehma
Copy link
Author

ahoehma commented Oct 17, 2024

@ahoehma do you have in your OpenAPI definition file another operationId "getProductLocalizations"?

No. I checked that many times :) The openapi.json looks fine to me.
And with 7.8.0 everything is also fine.
It must be something new since 7.9.0.

@CaptainAye
Copy link
Contributor

CaptainAye commented Oct 20, 2024

Looks like the issue is related to the fact that you're having more than one tag per operationId.
The issue was introduced by the fix for #19715 and looks like it's being addressed in #19913

@GreenRover
Copy link

+1

@ahoehma
Copy link
Author

ahoehma commented Oct 24, 2024

OT: Originally I thought the tags such there to leave some more "details" about my api and have some quick filter in swagger-ui. But meanwhile I realized that for each tag the generator creates it's own interface, ServiceApi, ReadApi etc. Since last version I started adding the api-version as tag which created just more none-sense interfaces like V123Api. Is there a best practice for tags?

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

Successfully merging a pull request may close this issue.

4 participants