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

Java code generation fails with id & setId field names #20484

Open
dhoffer opened this issue Jan 16, 2025 · 4 comments
Open

Java code generation fails with id & setId field names #20484

dhoffer opened this issue Jan 16, 2025 · 4 comments

Comments

@dhoffer
Copy link

dhoffer commented Jan 16, 2025

Description

I have a Java model class that has these fields (and more).

private String id;
private String setId;

openapi-generator version

7.10.0

OpenAPI declaration file content or url
type: object
      properties:
        id:
          description: "Unique identifier of the record."
          maxLength: 36
          minLength: 1
          type: string
          example: 3b0b1b1a-a3c0-4267-894a-0c40cb84a5af
        setId:
          description: User-defined ID.
          type: string
          example: 2b0b1b1a-a3c0-4267-894a-0c40cb84a5af
Generation Details
Steps to reproduce

The issue is that the codegen tool has correctly made the setId() method for the id field but then it makes another setId() method for the setId field which is incorrect. It should be making a setSetId() method for the setId field.

How to fix/resolve this?

@wing328
Copy link
Member

wing328 commented Jan 16, 2025

please give it a try with the name mapping option: https://github.com/openapitools/openapi-generator/blob/master/docs/customization.md#name-mapping

@dhoffer
Copy link
Author

dhoffer commented Jan 18, 2025

I am using the Maven plugin and could not determine how to use the name mapper with the plugin, How would I add that to the configOptions?

      <cleanupOutput>true</cleanupOutput>
      <skipValidateSpec>false</skipValidateSpec>
      <useJakartaEe>true</useJakartaEe>
      <dateLibrary>java8</dateLibrary>
      <library>apache-httpclient</library>
      <identifierNamingConvention>snake_case</identifierNamingConvention>

@dhoffer
Copy link
Author

dhoffer commented Jan 18, 2025

Here is an example of what I tried and it didn't work.

            <cleanupOutput>true</cleanupOutput>
            <nameMappings>setId=similarSetId</nameMappings>

@dhoffer
Copy link
Author

dhoffer commented Jan 18, 2025

I just figured out how to do this, it must be set in the configuration element group and then set like this:

<nameMappings> <nameMapping>setId=userDefinedId</nameMapping> </nameMappings>

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

No branches or pull requests

2 participants