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] Invalid code generated for enums of type number for Jackson JSON-libraries: inserted BigDecimal.valueOf is invalid #20506

Open
wienczny opened this issue Jan 20, 2025 · 0 comments

Comments

@wienczny
Copy link
Contributor

Code generation for generator java with a Jackson JSON library changed between 7.9.0 and 7.10.0 for enums. In 7.10.0 the generated code is invalid.
When an enum is type number there is an additional BigDecimal.valueOf inserted. This has been testet with serveral libraries:

affected:

  • apache-httpclient
  • restclient
  • native

not affected

  • okhttp-gson

Degression is between 7.9.0 and 7.10.0

An example can be found here:
https://developer.dhl.com/sites/default/files/2025-01/dpdhl-express-api-2.12.1_swagger_0.yaml

        outputImageProperties:
          description: 'Here you can modify label, waybillDoc, invoice and shipment receipt properties'
          type: object
          minProperties: 1
          properties:
            printerDPI:
              description: >-
                Printer DPI Resolution for X-axis and Y-axis (in DPI) for transport
                label and waybill document output
              type: number
              enum:
                - 200
                - 300
              example: 300

In 7.10.0 this generates to

  public enum PrinterDPIEnum {
    NUMBER_200(BigDecimal.valueOf(new BigDecimal("200"))),
    
    NUMBER_300(BigDecimal.valueOf(new BigDecimal("300")));

In 7.9.0 this used to be:

  public enum PrinterDPIEnum {
    NUMBER_200(new BigDecimal("200")),
    
    NUMBER_300(new BigDecimal("300"));
Generation Details
docker run --rm -v "/tmp/foo:/local" openapitools/openapi-generator-cli:v7.10.0 generate \
                                       -i https://developer.dhl.com/sites/default/files/2025-01/dpdhl-express-api-2.12.1_swagger_0.yaml \
                                       -g java --library=native \
                                       -o /local/out/java
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

1 participant