Skip to content
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

Add openapi-typescript-helpers package #1300

Merged
merged 2 commits into from
Aug 17, 2023
Merged

Add openapi-typescript-helpers package #1300

merged 2 commits into from
Aug 17, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Aug 17, 2023

Changes

Adds openapi-typescript-helpers package, as suggested in #1259. Still a bit of a WIP, but will be nice just being able to have types for anything that comes up. That way we have it

0a045621-286c-4dd4-9f76-f76e3ae5b24e_text

How to Review

  • Tests should pass (openapi-fetch especially)

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 Aug 17, 2023

🦋 Changeset detected

Latest commit: 9ac668b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-fetch Patch

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

@cloudflare-pages
Copy link

cloudflare-pages bot commented Aug 17, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9ac668b
Status:⚡️  Build in progress...

View logs

@drwpow drwpow force-pushed the types-helper-package branch 7 times, most recently from 61c5dd4 to d4e989d Compare August 17, 2023 06:25
@drwpow drwpow marked this pull request as ready for review August 17, 2023 06:34
/** Return `content` for a Response Object */
export type ResponseContent<T> = T extends { content: any } ? T["content"] : unknown;
/** Return `requestBody` for an Operation Object */
export type OperationRequestBody<T> = T extends { requestBody?: any } ? T["requestBody"] : never;
Copy link
Contributor Author

@drwpow drwpow Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all the types got renamed. As I was writing down JSDoc descriptions for each, I realized that none of the names made sense (they were close, but didn’t accurately describe how they were actually functioning… in fairness a lot of refactoring happened, though, and the names probably were not kept up with well)

}

return {
/** Call a GET endpoint */
async GET<P extends PathsWith<Paths, "get">>(url: P, init: FetchOptions<FilterKeys<Paths[P], "get">>) {
async GET<P extends PathsWithMethod<Paths, "get">>(url: P, init: FetchOptions<FilterKeys<Paths[P], "get">>) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a related note: type names became more verbose, but for the sake of clarity

export type RequestOptions<T> = Params<T> &
RequestBody<T> & {
export type ParamsOption<T> = T extends { parameters: any } ? { params: NonNullable<T["parameters"]> } : DefaultParamsOption;
export type RequestBodyOption<T> = OperationRequestBodyContent<T> extends never ? { body?: never } : undefined extends OperationRequestBodyContent<T> ? { body?: OperationRequestBodyContent<T> } : { body: OperationRequestBodyContent<T> };
Copy link
Contributor Author

@drwpow drwpow Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types that were left in here are opinionated and meant specifically for openapi-fetch. They are still exported so they can still be used. But hints at “you’re probably only importing this because you want to mimic / mock openapi-fetch behavior specifically” while leaving the generic usecases to the new types package

@drwpow drwpow merged commit 5939e20 into main Aug 17, 2023
7 of 8 checks passed
@drwpow drwpow deleted the types-helper-package branch August 17, 2023 06:56
@github-actions github-actions bot mentioned this pull request Aug 17, 2023
@drwpow drwpow mentioned this pull request Aug 30, 2023
3 tasks
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.

None yet

1 participant