-
-
Notifications
You must be signed in to change notification settings - Fork 529
Add multipart requestBody support, update docs #1189
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
Conversation
🦋 Changeset detectedLatest commit: 457cd95 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Deploying with
|
Latest commit: |
457cd95
|
Status: | ✅ Deploy successful! |
Preview URL: | https://38c6eee7.openapi-ts.pages.dev |
Branch Preview URL: | https://handle-multipart.openapi-ts.pages.dev |
@@ -38,38 +40,48 @@ export type PathsWith<Paths extends Record<string, PathItemObject>, PathnameMeth | |||
}[keyof Paths]; | |||
/** Find first match of multiple keys */ | |||
export type FilterKeys<Obj, Matchers> = { [K in keyof Obj]: K extends Matchers ? Obj[K] : never }[keyof Obj]; | |||
/** handle "application/json", "application/vnd.api+json", "appliacation/json;charset=utf-8" and more */ | |||
export type JSONLike = `${string}json${string}`; | |||
export type MediaType = `${string}/${string}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprioritize application/json
and just accept… anything
Of course, this may cause issues where a text/plain
comes before application/json
. But I’d personally rather have someone put forward that scenario where that happens in the real world.
data = await response.clone().text(); | ||
} | ||
const cloned = response.clone(); | ||
data = typeof cloned[parseAs] === "function" ? await cloned[parseAs]() : await cloned.text(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change: don’t catch()
; just let the error bubble up if there’s a parsing error
body: typeof requestBody === "string" ? requestBody : JSON.stringify(requestBody), | ||
}); | ||
}; | ||
if (requestBody) requestInit.body = bodySerializer(requestBody as any); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change: don’t send body: undefined
@@ -35,7 +35,7 @@ jobs: | |||
runs-on: ubuntu-latest | |||
strategy: | |||
matrix: | |||
node-version: [16.x, 18.x, 20.x] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping Node 16 testing cuz it’ll be EOL in 3 months
Changes
Fixes #1123 and #1157 by deprioritizing JSON-like media types (
application/json
, etc.) and accepting any content type (such asmultipart/form-data
,application/x-www-form-urlencoded
, etc.Also adds a
bodySerializer
option to use things likeFormData
if desired.How to Review
Tests should pass.
Checklist