OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-axios] generates incorrect boolean enum from V2 spec

Open
#15,178 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

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Incorrect generation of model for boolean enum type. It is similar problem to linked similar issue/pr. I know the schema is strange but I have no control over it.

openapi-generator version

latest docker image, 6.6.0-SNAPSHOT at the time of writing

OpenAPI declaration file content or url
{
  "swagger": "2.0",
  "info": {
    "title": "",
    "version": ""
  },
  "host": "test.com",
  "basePath": "/api",
  "paths": {},
  "definitions": {
    "Commodity": {
      "type": "object",
      "properties": {
        "active": {
          "type": "boolean",
          "format": "boolean",
          "enum": [
            "true",
            "false"
          ]
        }
      }
    }
  }
}
Generation Details

Config can be seen below. Generated output creates:

/**
    * @export
    * @enum {string}
    */
export enum CommodityActiveEnum {
    TRUE = true,
    FALSE = false
}

which is incorrect. Should be smth like type = true | false or normalize to strings

Steps to reproduce
  1. Create some dir for docker volume with config.yaml, schema.yaml (content above), and generate.sh script (or run inline)
#!/bin/bash

VOLUME_PATH=...
docker run --rm \
  -v "${VOLUME_PATH}":/openapi openapitools/openapi-generator-cli generate \
  -i /openapi/schema.yaml \
  -g typescript-axios \
  -o /openapi/output" \
  -c /openapi/config.yaml \
  --skip-operation-example

config.yaml:

snapshot: false
supportsES6: true
allowUnicodeIdentifiers: true
apiPackage: api
modelPackage: model
withSeparateModelsAndApi: true
enumPropertyNaming: UPPERCASE
stringEnums: true
useSingleRequestParameter: true
  1. run ./generate.sh
Related issues/PRs

Related to https://github.com/OpenAPITools/openapi-generator/issues/9024

Suggest a fix

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

Start by running generate.sh with config.yaml and schema.yaml using the typescript-axios generator, then inspect the generated CommodityActiveEnum. Compare the boolean enum output with the expected TypeScript representation and trace the generator behavior responsible; the issue is done when generation produces valid, intended TypeScript for this schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.