swagger-api / swagger-api/swagger-codegen
[TypeScript] Any typescript codegen removes underscores and forces enum value naming to camelCase (thus breaking snake_case API's, see Zalando API guidelines) [with fix, 1 LOC]
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The abstract TypeScript codegen implementation has a bug that breaks any Enumeration described in any swagger.json file basically turning enum values like "TYPE_A" into "TYPEA":
Also, camelCase is forced, ignoring modelPropertyNaming option:
Swagger-codegen version
master, rev. e11d7646091ab75780fc69be938218ef5da15715
Swagger declaration file content or url
Any swagger.json that specifies Enum values in format as: A_B_C
https://raw.githubusercontent.com/logzio/public-api/master/alerts/swagger.json
Command line used for generation
Steps to reproduce
java -jar ./swagger-codegen-cli.jar generate \
-i https://raw.githubusercontent.com/logzio/public-api/master/alerts/swagger.json \
-l typescript-fetch \
-D modelPropertyNaming=original \
-o ./src
Or:
- https://editor.swagger.io/#
- Import from URL: https://raw.githubusercontent.com/logzio/public-api/master/alerts/swagger.json
- Generate client: typescript-fetch
- Extract zip -> open api.ts -> Line 323, OperationEnum
Related issues/PRs
Unknown
Suggest a fix/enhancement
Instead of manually replacing special characters and forcing camelCase, call:
String enumName = sanitizeName(name);
It fixes the issue for me but (expectedly) breaks the tests.
Unfortunately, I have no time for a PR process atm.
For anyone running into the same issue, I hope this helps.
btw: Namespaces are deprecated and to be replaced by ES6 modules syntax. If you try to compile swagger-codegen based TypeScript libraries with Babel 7 instead of tsc, this is already impossible and the code will break once TypeScript removes support for namespaces officially.
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 in modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java at the referenced lines, then reproduce with the typescript-fetch command and logzio swagger.json. Verify that generated api.ts preserves enum underscores and respects modelPropertyNaming=original, while updating the relevant tests that currently fail with the proposed sanitization change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100