Skip to content

Wrong generated type when processing enums containing "null" #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FedeBev opened this issue Feb 17, 2021 · 3 comments
Closed

Wrong generated type when processing enums containing "null" #482

FedeBev opened this issue Feb 17, 2021 · 3 comments

Comments

@FedeBev
Copy link
Contributor

FedeBev commented Feb 17, 2021

Hi there,

with swagger 2 definition like the following

field:
    type: string
    enum: ["N", "L", null]
    nullable: true

the following code is generated

"field"?: (('N') | ('L') | ()) | null;

resulting in a syntax error: SyntaxError: '=>' expected.

This could be related to #447 and #234

openapi-typescript version: 3.0.1

@gr2m
Copy link
Contributor

gr2m commented Feb 17, 2021

Could you create a pull request with a failing test, and we take it from there?

@FedeBev
Copy link
Contributor Author

FedeBev commented Mar 2, 2021

Hi @gr2m,

I didn't have much time to deep dive into the project, however I've created a PR (#492) with a failing test for both V2 and V3, hopefully in the right place 😃

The PR #492 should now fix the issue

drwpow pushed a commit that referenced this issue Mar 2, 2021
* add failing test

* fix generated type when processing enums containing "null"

Fix issue #482

* remove useless code

* avoid double null when enum contains null and is nullable

Co-authored-by: Federico Bevione <[email protected]>
@gr2m
Copy link
Contributor

gr2m commented Mar 2, 2021

Thanks! Closed via #492 👏🏼

@gr2m gr2m closed this as completed Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants