-
Notifications
You must be signed in to change notification settings - Fork 61
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): handle type definitions for request body params #6018
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CalebBarnes
commented
Jan 16, 2025
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.
a168c12
to
7cacefc
Compare
…PI client definition comment Improve DX by adding links to docs and small code sample.
- 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.
YujohnNattrass
previously approved these changes
Jan 16, 2025
DanielSLew
previously approved these changes
Jan 16, 2025
…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.
dc02142
YujohnNattrass
approved these changes
Jan 16, 2025
YujohnNattrass
approved these changes
Jan 16, 2025
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds type definitions for the
body
parameter in methods that accept a request body, while maintaining proper handling for optional andvoid
parameters. It ensures that methods with optional or no parameters are typed correctly.Changes
Reference Documentation and Example:
NetlifyAPI
client definition comment to include links to the Open API Reference and Online DocumentationRequest Body Types:
body
parameters for methods withapplication/json
orapplication/octet-stream
request bodies.application/json
bodies as JSON objects or functions returning JSON objects (with type definitions derived from the@netlify/open-api
schema).application/octet-stream
bodies as Node.jsReadStream
or functions returning aReadStream
.Optional Parameters:
IsRequestBodyOptional
to check if all properties in the request body are optional.OperationParams
type to conditionally include thebody
parameter only when applicable and correctly handle optional request bodies.void
).Helper Types:
HasRequestBody
: Determines if a method supports a request body.RequestBody
: Extracts the request body type based on the operation.IsParamsOrRequestBodyRequired
: Determines if any path, query, or request body parameters are required.CombinedParamsAndRequestBody
: Combines path, query, and request body parameters into a single type.How it looks in editor
operation


createSite
with request body typeapplication/json
using types derived from@netlify/open-api
:operation


uploadDeployFile
with request body typeapplication/octet-stream
:For us to review and ship your PR efficiently, please perform the following steps:
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.
your code follows our style guide and passes our tests.
A picture of a cute animal (not mandatory, but encouraged)