OpenAPITools / OpenAPITools/openapi-generator

[BUG] getter Method is not correct in generated model

Open
#13,768 0 comments 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

When generating a client library, the getters for a field is getBigDecimal() and its return type is BigDecimal but there is no import for BigDecimal data type.
So, when i am using type-mappings then return type is changed to fully qualified class name and getters method is also changed to getjava.math.BigDecimal() . (getter method should not have changed )

public java.math.BigDecimal getjava.math.BigDecimal() throws ClassCastException {
return (java.math.BigDecimal)super.getActualInstance();
}

--type-mappings BigDecimal=java.math.BigDecimal

i tried using import-mappings but generator is not adding import for BigDecimal.
--import-mappings BigDecimal=java.math.BigDecimal

openapi-generator version - 6.2.0
Library - jersey2

OpenAPI declaration file content :
image

Command line used for generation

As per naming conventions, this is wrong 👍
https://stackoverflow.com/questions/2948083/naming-convention-for-getters-setters-in-java

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

Reproduce generation for the reported OpenAPI declaration with the jersey2 library, using the BigDecimal type-mappings and import-mappings options. Inspect the generated model getter and imports; done means the getter remains getBigDecimal(), returns java.math.BigDecimal, and the generated Java code has the required import or valid fully qualified type usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.