-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Generate typescript types from rest API docs #25123
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
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.
Looking nice. Just a few suggestions.
For the camel case naming they recommend keeping it as snake case in their readme. (project goals section) Maybe we should do that and get completely rid of camel case.
If we still want to enforce camel case, as a last resort we could use the template litéral + conditionnal type recursion, and we could define this: (add this to the generated file)
type SnakeToCamelCase<word extends string> =
word extends `${infer firstWord}_${infer rest}`
? `${firstWord}${Capitalize<SnakeToCamelCase<rest>>}`
: word;
type KeysToCamelCase<T> = {
[K in keyof T as SnakeToCamelCase<string & K>]: T[K]
}Then we only need to wrap our generated type like so: (in the generation step)
export type UserCollectionItem = KeysToCamelCase<components['schemas']['UserCollectionItem']>;
export type User = KeysToCamelCase<components['schemas']['User']>;
export type UserCollection = KeysToCamelCase<components['schemas']['UserCollection']>;
export type ConnectionCollectionItem = KeysToCamelCase<components['schemas']['ConnectionCollectionItem']>;| }); | ||
| }; | ||
|
|
||
| function generate(file) { |
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.
Should we also push the licence directly, or are we counting on the pre-commit hook to do that for us ?
|
@pierrejeambrun Good idea to add a Also, fixed spelling errors and auto-adding the license to the generated file. |
|
Good job on the nested type 👍 Should we add the type-generation step to the static-checks (pre-commit + CI)? What I mean by that is, if someone update the API, these changes should be reflected in the ts types. (And potentially linting error would arise) Plus manually having to regenerate the types each time we pull from main in case the open api spec is updated is not ideal. |
jedcunningham
left a comment
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.
Looks good, though there are some static check failures to clean up.
|
#25167 will handle the pre-commit hook to auto-generate the type file |

Use openapi-typescript to generate types for all rest API data. This keeps a single source of truth vs manually writing all the data endpoint types.
Also, found a bug where
map_indexwas missing from the TaskInstance schema^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.