Skip to content

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

Merged
merged 2 commits into from
Oct 8, 2023
Merged

Fix openapi fetch types #1378

merged 2 commits into from
Oct 8, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Oct 8, 2023

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 custom fetch test.

How to Review

  • Tests updated; tests should pass.

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@changeset-bot
Copy link

changeset-bot bot commented Oct 8, 2023

⚠️ No Changeset found

Latest commit: b112cfe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -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",
Copy link
Contributor Author

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;
Copy link
Contributor Author

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"] };
Copy link
Contributor Author

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();
Copy link
Contributor Author

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.
Copy link
Contributor Author

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.

@drwpow drwpow merged commit ca6f394 into main Oct 8, 2023
@drwpow drwpow deleted the fix-openapi-fetch-types branch October 8, 2023 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant