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

fix(js-client): add type definitions for operation method opts argument #6021

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

CalebBarnes
Copy link
Contributor

Summary

All dynamic operation methods can have a second arg opts to pass any additional properties to node-fetch RequestInit. This change adds the type definition for the opts argument.

Also allow passing undefined for params argument for methods that don't accept any params but still might want to pass opts.

example:

const user = await client.getCurrentUser(undefined, {
  headers: {
    'X-Some-Header': 'custom value',
  },
})

For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

Base automatically changed from fix/js-client-types-request-body to main January 16, 2025 22:07
Handling type definitions for requestBody in API schema while still
taking into consideration optional / void params if all path, query, and
requestBody keys are optional.
- combined the request body type with the Params type
- handle cases where request body properties are optional
- handle cases where all params and request body are optional
- allow 'application/json' body to be a JSON object or a function
returning one
- allow 'application/octet-stream' body to be a Node.js ReadStream or a
function returning one
- simplify by extracting repetitive logic to helper types like
`IsParamsOrRequestBodyRequired` and `IsRequestBodyOptional` etc.
…dy for clarity

These types are responsible for adding detailed annotations to the
`body` parameter of API methods, such as describing its usage and
examples for `application/json` and `application/octet-stream`. The new
names make their purpose more explicit and improve readability for
future maintenance and usage.
All dynamic operation methods can have a second arg `opts` to pass any
additional properties to `node-fetch` RequestInit. This adds the type
definition for the `opts` argument.
@CalebBarnes CalebBarnes force-pushed the fix/js-client-types-add-method-opts branch from 8e7fb08 to 2cfac31 Compare January 16, 2025 22:10
added this export by accident, just removing it
@CalebBarnes CalebBarnes marked this pull request as ready for review January 16, 2025 22:12
@CalebBarnes CalebBarnes requested a review from a team as a code owner January 16, 2025 22:12
@CalebBarnes CalebBarnes changed the title fix(js-client): add type definitions for dynamic operation method opts argument fix(js-client): add type definitions for operation method opts argument Jan 16, 2025
@kodiakhq kodiakhq bot merged commit 02af82a into main Jan 16, 2025
33 checks passed
@kodiakhq kodiakhq bot deleted the fix/js-client-types-add-method-opts branch January 16, 2025 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants