-
-
Notifications
You must be signed in to change notification settings - Fork 543
Encode the request body if Content-Type
header is x-www-form-urlencoded
#2096
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
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
|
@@ -72,7 +72,7 @@ export default function createClient(clientOptions) { | |||
}); | |||
} | |||
|
|||
const serializedBody = body === undefined ? undefined : bodySerializer(body); | |||
const serializedBody = body === undefined ? undefined : bodySerializer(body, headers); |
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.
So these are the headers unique to this request (probably could be named better). Below on line 92
, we merge all the headers together. We should probably move that up, adn pass that in here to bodySerializer
. That way it takes into account headers that users have set in their createClient()
call, and it handles the normalization for you so it’s always a Header
type (and you aren’t dealing with what the user passed in)
This approach looks good to me, and good test! But before we merge, we’ll want to:
|
@obulat Still willing to accept this PR with the changes mentioned! |
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.
This PR is close enough! I’ll make the changes post-merge to make sure we’re not grabbing incorrect/stale headers, and add a changeset retroactively.
* Update schema-object.ts * chore(deps): update dependency msw to v2.7.6 (openapi-ts#2287) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @types/node to v22.15.10 (openapi-ts#2293) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @shikijs/vitepress-twoslash to v3.4.0 (openapi-ts#2298) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @arethetypeswrong/cli to ^0.18.0 (openapi-ts#2272) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency execa to v9.5.3 (openapi-ts#2303) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(metadata): fix thunk type detection (openapi-ts#2125) * Don't remove `null` type if a default is present. (openapi-ts#2145) * Don't remove `null` type if a default is present. * Don't remove `null` type from enums if default is present. * Don't remove `null` type if default is present (legacy) * [ci] release (openapi-ts#2307) * [ci] release * Add 2145 manually --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> * chore(deps): update dependency @types/react to v18.3.21 (openapi-ts#2218) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(openapi-fetch): fix overriding baseUrl per request without overriding default baseUrl (openapi-ts#2157) * Support $ref into `paths` (openapi-ts#2185) * React query handle 204 or zero content length (openapi-ts#2235) * fix(openapi-react-query): Handle 204 or zero Content-Length header by returning data as null * fix(openapi-react-query): updated and added 204 & zero Content-Length queryFn tests * chore(openapi-react-query): Fixed linting in test * chore(deps): update dependency @arethetypeswrong/cli to v0.18.1 (openapi-ts#2306) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency msw to v2.8.2 (openapi-ts#2304) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Speakeasy URL (openapi-ts#2302) * chore(deps): update dependency @tanstack/react-query to v5.75.7 (openapi-ts#2301) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency lint-staged to v15.5.2 (openapi-ts#2297) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * feat(swr-openapi): add custom error types to query builder (openapi-ts#2147) * chore(deps): update vitest monorepo to v3 (openapi-ts#2284) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Encode the request body if Content-Type set (openapi-ts#2096) * Improve header handling (openapi-ts#2308) * [ci] release (openapi-ts#2309) * [ci] release * Release additional packages --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> * chore: update openapi-fetch test fixture (openapi-ts#2313) * Build packages with unbuild to improve CJS support (openapi-ts#2310) * [ci] release (openapi-ts#2314) * [ci] release * Fix major bump --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> * Update code of conduct source (openapi-ts#2316) Signed-off-by: Emmanuel Ferdman <[email protected]> --------- Signed-off-by: Emmanuel Ferdman <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Martin Paucot <[email protected]> Co-authored-by: Theron Luhn <[email protected]> Co-authored-by: openapi-ts-bot <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> Co-authored-by: Luis Merino <[email protected]> Co-authored-by: Duncan Beevers <[email protected]> Co-authored-by: Wheelebin <[email protected]> Co-authored-by: Nolan Di Mare Sullivan <[email protected]> Co-authored-by: しゅーまい <[email protected]> Co-authored-by: Olga Bulat <[email protected]> Co-authored-by: Emmanuel Ferdman <[email protected]>
@drwpow, sorry I couldn't finish up the work here, and thank you so much for merging! |
Oh no worries at all; the maintainers and I all had individual things come up that made reviews earlier in the year slower than we’d like too. Thanks again for the work! 🙏 |
Changes
Fixes #2069
This PR updates the
defaultBodySerializer
to correctly serialize the body ifContent-Type
header is set tox-www-form-urlencoded
. This is useful for OAuth2 token requests.How to Review
I'm not sure about the headers: what type are they, and are they normalized?
I added handling for both a plain JS object (
headers['Accept-Content']
) and aHeaders
object (headers.get['Accept-Content']
), as well as both capitalized and lower-case versions.Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)