-
- Notifications
You must be signed in to change notification settings - Fork 594
Add openapi-typescript-helpers package #1300
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
🦋 Changeset detectedLatest commit: 9ac668b 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 |
3a1445c to adcd95a Compare 61c5dd4 to d4e989d Compare d4e989d to 4eed424 Compare | /** 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; |
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.
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">>) { |
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.
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> }; |
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.
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
b6a33d1 to 9ac668b Compare * Add openapi-typescript-helpers package * Add add’l package.json info
Changes
Adds
openapi-typescript-helperspackage, 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 itHow to Review
openapi-fetchespecially)Checklist
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)