Skip to content
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

Property values with defaults are being incorrectly typed as possibly undefined when they shouldn't be. #584

Closed
rustyconover opened this issue May 5, 2021 · 7 comments · Fixed by #613

Comments

@rustyconover
Copy link

Hi Team,

Thank you for a great module.

It seems the logic in the link below is insufficient to handle if a property able to be defined or undefined.

https://github.com/drwpow/openapi-typescript/blob/4c51afc45f449943bc9e2c58639606b15aaa88b8/src/transform/parameters.ts#L58

If a property isn't required in an object but that property has a default value specified, that property will never be undefined. See the docs at:

https://swagger.io/docs/specification/describing-parameters/

Rusty

@mehalter
Copy link
Contributor

mehalter commented May 5, 2021

This was accidentally mentioned in the above PR, sorry for the confusion!

@rustyconover
Copy link
Author

Okay I was just looking at the diff and it didn't make sense.

@rustyconover
Copy link
Author

I have a partial fix but I can't figure out how to resolve the refs at runtime.

@rustyconover
Copy link
Author

I'm unsure of how to call

unrefComponent(components: any, ref: string): any 

in transformParametersArray

rustyconover added a commit to rustyconover/openapi-typescript that referenced this issue May 6, 2021
rustyconover added a commit to rustyconover/openapi-typescript that referenced this issue May 6, 2021
rustyconover added a commit to rustyconover/openapi-typescript that referenced this issue May 9, 2021
drwpow added a commit that referenced this issue May 25, 2021
drwpow added a commit that referenced this issue May 25, 2021
drwpow added a commit that referenced this issue May 27, 2021
@drwpow drwpow reopened this May 27, 2021
@gr2m
Copy link
Contributor

gr2m commented May 28, 2021

@drwpow #613 marked types for request parameters as required if they have a default value, but that is not correct, I think the change should only apply to response types. I'm looking into it

@rustyconover
Copy link
Author

@gr2m Please see my comment: #613 (comment)

@drwpow
Copy link
Contributor

drwpow commented Jun 3, 2021

This is now supported, though it must be enabled with the --default-non-nullable flag. This may be unexpected (unsafe) behavior for those not expecting it, but users are still able to opt in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants