OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] generates incorrect boolean enum from V2 spec
Nobody has claimed this yet.
- 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
- Create some dir for docker volume with
config.yaml,schema.yaml(content above), andgenerate.shscript (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
- run
./generate.sh
Related issues/PRs
Related to https://github.com/OpenAPITools/openapi-generator/issues/9024
Suggest a fix
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 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