-
-
Notifications
You must be signed in to change notification settings - Fork 528
Fix openapi fetch types #1378
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
Fix openapi fetch types #1378
Conversation
|
@@ -70,7 +70,7 @@ | |||
"del-cli": "^5.1.0", | |||
"esbuild": "^0.19.4", | |||
"nanostores": "^0.9.3", | |||
"openapi-typescript": "workspace:^", | |||
"openapi-typescript": "^6.7.0", |
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.
Locks openapi-typescript to v6 temporarily
: never; | ||
: DefaultParamsOption; | ||
// v7 breaking change: TODO uncomment for openapi-typescript@7 support | ||
// : never; |
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 is a minor breaking change: in openapi-typescript@7
, more structures are generated as never
, including all parameters
, so the inference is improved. But in v6, missing items are simply omitted. This is the only place that makes a difference, but it’s still a breaking change nonetheless and it means openapi-fetch
will need a breaking release when the time comes.
|
||
export type RequestBodyOption<T> = OperationRequestBodyContent<T> extends never | ||
? { body?: never } | ||
: undefined extends OperationRequestBodyContent<T> | ||
? { body?: OperationRequestBodyContent<T> } | ||
: { body: OperationRequestBodyContent<T> }; | ||
|
||
export type FetchOptions<T> = RequestOptions<T> & | ||
Omit<RequestInit, "body"> & { fetch?: ClientOptions["fetch"] }; |
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.
Doesn’t change the option itself; just moved to be with the other options (it was inconsistent here)
const customResponse = await client.GET("/self", { fetch: customFetch }); | ||
expect(customResponse.data).toBe(data); | ||
// assert global fetch was never called | ||
expect(fetchMocker).not.toHaveBeenCalled(); |
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 was an important part missing from the original test—testing that global fetch
wasn’t actually invoked (we could assume, based on the data, but we weren’t explicitly checking).
// Note | ||
// This is a copy of index.test.ts, but uses generated types from openapi-typescript@7 (beta). | ||
// This tests upcoming compatibility until openapi-typescript@7 is stable and the two tests | ||
// merged together. |
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.
Temporary 2nd test file added to make sure openapi-typescript@7 support is easy when the time comes.
Changes
In the v7 rewrite (#1368), openapi-fetch’s types accidentally inherited a minor breaking change. This reverts that.
Also removes
examples/
accidentally getting published to the npm package. And improves the customfetch
test.How to Review
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)