OpenAPITools / OpenAPITools/openapi-generator
[REQ] Java generator should be able to use BigDecimal instead of float for "float" number in generated Model classes.
Nobody has claimed this yet.
- 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.
Let's say we have this definition:
amount:
type: "number"
format: "float"
description: "Amount of money"
Java generator will create model class with property amount of java type Float. This is good for most uses, but it's infamously bad for storing money.
Swagger spec itself is agnostic about how "float" type is implemented - all it means is that it's floating point number with (potentially) unlimited precision (same applies for JSON number type definition).
Describe the solution you'd like
Better option here would be to generate classes with BigDecimal instead which is perfect for money. I expect that this would be opt-in so by default the floats would be generated and only if you configure BigDecimals then these would be used.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Java generator's mapping for OpenAPI number types and its existing configuration options. Add an opt-in BigDecimal path while preserving Float as the default, then verify generated model output for both settings with the generator's relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100