OpenAPITools / OpenAPITools/openapi-generator

[BUG] When double is specified with "maximum" it uses scientific notation

Open
#22,341 1 comment 1 reaction 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

Description

When double is specified with maximum, It generates Java model with scientific notation

@DecimalMax(value = "1.0E+15")

This causes error response text to be not readable.

openapi-generator version

version 7.17.0

OpenAPI declaration file content or url
    CurrencyAndAmount:
      required:
        - amount
      type: object
      properties:
        amount:
          type: number
          format: double
          minimum: 0
          maximum: 999999999999999.99
          multipleOf: 0.01
          description: 15 digit and upto 2 decimals
          example: 100.01

Generation Details

openapi-generator-cli generate
-i ./src/main/resources/openapi.yaml
-g spring
-o ./target/generated-sources/openapi
--model-package com.example.api.generated.model
--api-package com.example.api.generated.api
--invoker-package com.example.api.generated.invoker
--type-mappings Double=java.math.BigDecimal
--additional-properties useSpringBoot=false,bigDecimalAsString=true,dateLibrary=java8,serializableModel=true,interfaceOnly=true,useTags=true

Steps to reproduce

when interface only is true, for java it generates like this

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/16312

But this was where they declared it as string.

Suggest a fix

I understand its functionally valid syntax, But is there a reason why its not added normal string ?

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

Use the supplied OpenAPI declaration and Java/Spring generation command to reproduce the generated @DecimalMax value. Inspect the Java generator path that renders maximum constraints and its existing regression tests. Done means the generated annotation preserves the maximum as a readable non-scientific decimal and the behavior is covered by a regression test.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.