swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[typescript-angular] not generating enums as enum type

Open Mattieeec3 opened this issue 5 years ago • 4 comments

Description

I have an enum in my swagger scheme, but after generating the typescript-angular client with swagger codegen, the generated 'enum' looks like below:

image

The generator should use the typescript enum type instead of creating a custom object.

Swagger-codegen version

2.4.17

Swagger declaration file content or url

https://pastebin.com/h9MK0NEQ

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i http://localhost:54371/swagger/v1/swagger.json -l typescript-angular -o .

Steps to reproduce

Generate angular-typescript client with the swagger declaration file

Related issues/PRs

/

Suggest a fix/enhancement

/

Mattieeec3 avatar Jan 27 '21 16:01 Mattieeec3

I have the same issue, tweaking the swagger config, I managed to get semantic strings generated but still no actual enums. Any ideas from the Swagger guys on this?

JosephDesmet avatar Jan 28 '21 09:01 JosephDesmet

I have the same issue

jfernandeze avatar Feb 04 '21 13:02 jfernandeze

Any updates or workarounds to fix this?

EDIT: I can get it to work if i use the config option: "stringEnums": true and add the enum names under x-enum-varnames in the swagger.json

JohnTraDolta avatar Jul 22 '21 07:07 JohnTraDolta

Any updates or workarounds to fix this?

EDIT: I can get it to work if i use the config option: "stringEnums": true and add the enum names under x-enum-varnames in the swagger.json

I can't confirm EDIT part. I have x-enum-varnames block in my spec and stringEnums option in command (see below). Neither for my version of generator, not for the latest it does not work. Same for axios vs angular language. Ended with a template-based workaround

java \
    --add-opens=java.base/java.util=ALL-UNNAMED \
    -Dmodels \
    -Dapis \
    -DsupportingFiles \
    -Dfile.encoding=UTF-8 \
    -DstringEnums=true \
    -jar ./swagger-codegen-cli-3.0.34.jar \
    generate \
    -i ./.etc/swagger-spec.json \
    -o ./.etc/sdk \
    -l typescript-axios

ZuBB avatar Jul 17 '25 08:07 ZuBB