Provide unserialized body to onRequest middleware #2542
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.
it's relatively expensive to have to clone the request to extract the body again in middleware, and as bodySerializer is provided as part of the options given to the requestSerializer it makes sense to also provide the original body here for advanced use cases that aren't covered by the bodySerializer.
In my case I'm dealing with an API that wants files uploaded to a secondary endpoint after the main request has completed, but I want to provide a good developer experience where they can provide a body such as
{ description: string, document: File }, to do this I need to traverse the body in a request middleware, extract the files (removing them from the serialized JSON body), link these files to the id (or new Request in a WeakMap), and then if they exist in the onResponse middleware actually post them.Changes
bodyas one of the properties of the options passed toonRequestmiddlewareChecklist
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)