fix(js-client): handle type definitions for request body params #6018
+135
−4
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)