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

Non-Required-Query-Parameters in Components are always generated as required #1052

Closed
1 task done
WtfJoke opened this issue Mar 14, 2023 · 0 comments · Fixed by #1053
Closed
1 task done

Non-Required-Query-Parameters in Components are always generated as required #1052

WtfJoke opened this issue Mar 14, 2023 · 0 comments · Fixed by #1053

Comments

@WtfJoke
Copy link

WtfJoke commented Mar 14, 2023

Description

When you define a non required query parameter in components section, it will always generated as required.

Name Version
openapi-typescript 6.2.0
Node.js 16.14.1
OS + version Ubuntu 22.04.2 LTS (WSL)

Reproduction

How can this be reproduced / when did the error occur?
We extended the petstore openapi yaml with an optional non required query parameters and let openapi-typescript generate the types.

  1. npx openapi-typescript https://gist.githubusercontent.com/WtfJoke/cc2f3d56262c19be11c035c2db90e1ea/raw/ac42890b9e4d0d1b8f76eb44434b5aedb32f21e5/petstore-openapi.yml --output generated/petstore.ts
  2. Open petstore.ts
  3. Verify that optionalUserNameQueryParam is of type string instead of type string | undefined

Expected result
optionalUserNameQueryParam in petstore.ts should be of type string | undefined
(in case it’s not obvious)

Checklist

Additional information
The modified petstore can be found in my gist here: https://gist.github.com/WtfJoke/cc2f3d56262c19be11c035c2db90e1ea (we simply added the optional query parameter to the components section, see revisions)

AplusKminus added a commit to AplusKminus/openapi-typescript that referenced this issue Mar 14, 2023
…i-ts#1052)

According to the OpenAPI 3.1.0 spec, a parameter is required if one of these matches:
- it has 'in: "path"'
- it has 'required: true'

See spec at Parameter Object - Fixed Fields:
https://spec.openapis.org/oas/v3.1.0#fixed-fields-9

Fixes openapi-ts#1052
AplusKminus added a commit to AplusKminus/openapi-typescript that referenced this issue Apr 3, 2023
…i-ts#1052)

According to the OpenAPI 3.1.0 spec, a parameter is required if one of these matches:
- it has 'in: "path"'
- it has 'required: true'

See spec at Parameter Object - Fixed Fields:
https://spec.openapis.org/oas/v3.1.0#fixed-fields-9

Fixes openapi-ts#1052
drwpow pushed a commit that referenced this issue Apr 7, 2023
)

* Add missing 'vite' dependency

* Ensure not required params are created as optional properties (#1052)

According to the OpenAPI 3.1.0 spec, a parameter is required if one of these matches:
- it has 'in: "path"'
- it has 'required: true'

See spec at Parameter Object - Fixed Fields:
https://spec.openapis.org/oas/v3.1.0#fixed-fields-9

Fixes #1052
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

Successfully merging a pull request may close this issue.

1 participant