OpenAPITools / OpenAPITools/openapi-generator

[BUG] Enums with numeric double values are passed to the models as strings, not numbers

Open
#19,606 0 comments 4 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?

See this file for debug output showing incorrect model value generation.

output.txt

Description
    DoubleChoice:
      type: number
      format: double
      enum:
        - 6.4
        - 9.9

This OpenAPI model should generate value: "6.4" but instead generates value: "'6.4'" with additional single-quote string markers.

Output, according to --global-property debugModels:

{
      "openApiType" : "DoubleChoice",
      "allowableValues" : {
        "enumVars" : [ {
          "name" : "number6Period4",
          "isString" : false,
          "value" : "'6.4'"
        }, {
          "name" : "number9Period9",
          "isString" : false,
          "value" : "'9.9'"
        } ],
        "values" : [ 6.4, 9.9 ]
      },
   /// rest omited
}

Meanwhile, integer types generate correctly:

{
      "openApiType" : "IntChoice",
      "allowableValues" : {
        "enumVars" : [ {
          "name" : "number64",
          "isString" : false,
          "value" : "64"
        }, {
          "name" : "number99",
          "isString" : false,
          "value" : "99"
        } ],
        "values" : [ 64, 99 ]
      },
/// rest omitted 
}
openapi-generator version

436a3e0744a2ce8208a7c3b8116fca6e7195143a

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  version: "1.1"
  title: Double Values Incorrect
servers:
  - url: "localhost"
    variables:
      host:
        default: localhost
paths:
  /getItem:
    get:
      operationId: getItem
      description: "Should return enum type of doubles"
      responses:
        "200":
          description: "get enum type of doubles"
          content:
            application/json:
              schema:
                $ref: "#components/schemas/NonStringEnums"


components:
  schemas:


    NonStringEnums:
      type: object
      description: "Has non-string enum types"
      required:
        - strChoice
        - intChoice
      properties:
        strChoice:
          $ref: "#/components/schemas/StrChoice"
        intChoice:
          $ref: "#/components/schemas/IntChoice"
        doubleChoice:
          $ref: "#/components/schemas/DoubleChoice"
        boolChoice:
          $ref: "#/components/schemas/BoolChoice"
    
    
    StrChoice:
      type: string
      enum:
        - FirstChoice
        - SecondChoice
    IntChoice:
      type: integer
      enum:
        - 64
        - 99
    DoubleChoice:
      type: number
      format: double
      enum:
        - 6.4
        - 9.9
    BoolChoice:
      type: boolean
      enum:
        - true
        - false
Steps to reproduce

java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -g dart -i .\incorrect_double_enum.yml -o incorrectDoubles --global-property debugModels > output.txt

Suggest a fix

Generate doubles choices like int choices, remove the quotation marks.

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 the issue with the provided OpenAPI YAML and Dart generation command using --global-property debugModels. Trace how the generator creates enumVars values; done means the debug output represents 6.4 and 9.9 without added single-quote markers, matching the integer enum behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, java, openapi
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.