-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
openapi-fetch improvements #1169
Conversation
🦋 Changeset detectedLatest commit: 3a61261 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 Cloudflare Pages
|
@@ -54,6 +56,31 @@ export type FetchResponse<T> = | |||
| { data: T extends { responses: any } ? NonNullable<FilterKeys<Success<T["responses"]>, JSONLike>> : unknown; error?: never; response: Response } | |||
| { data?: never; error: T extends { responses: any } ? NonNullable<FilterKeys<Error<T["responses"]>, JSONLike>> : unknown; response: Response }; | |||
|
|||
/** Call URLSearchParams() on the object, but remove `undefined` and `null` params */ |
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 QoL improvement: yes, the library did use new URLSearchParams()
as the default. But handling undefined
/ null
params is annoying to have to implement one’s own querySerializer
for.
|
||
/** Construct URL string from baseUrl and handle path and query params */ | ||
export function createFinalURL<O>(url: string, options: { baseUrl?: string; params: { query?: Record<string, unknown>; path?: Record<string, unknown> }; querySerializer: QuerySerializer<O> }): string { | ||
let finalURL = `${options.baseUrl ? options.baseUrl.replace(TRAILING_SLASH_RE, "") : ""}${url as string}`; |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
} | ||
|
||
/** Construct URL string from baseUrl and handle path and query params */ | ||
export function createFinalURL<O>(url: string, options: { baseUrl?: string; params: { query?: Record<string, unknown>; path?: Record<string, unknown> }; querySerializer: QuerySerializer<O> }): 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.
createFinalURL()
is now exposed for testing (#1161)
da2d8a5
to
9ddc881
Compare
Changes
Fixes:
finalUrl
#1161baseUrl
andpath
may result in invalid URLs #1150✨ new
parseAs
optionTo address the handling of non-JSON responses (#1123, #1159), you can now parse the response as something other than
.json()
parseAs
takes any of the following options:json
text
arrayBuffer
blob
stream
(this skips parsing, and returns the Response.body as-is)The reason for the manual detection is:
Content-Type
header isn’t possible because it could be wrong or ambiguous (e.g. it’s not clear fromContent-Type
alone when someone may want a.blob()
vs.arrayBuffer()
).arrayBuffer()
in certain instances)How to Review
Tests should pass
Checklist
examples/
directory updated (only applicable for openapi-typescript)