-
-
Notifications
You must be signed in to change notification settings - Fork 531
feat: root types #1599
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
feat: root types #1599
Conversation
|
@@ -75,6 +75,7 @@ | |||
"del-cli": "^5.1.0", | |||
"esbuild": "^0.20.1", | |||
"execa": "^7.2.0", | |||
"scule": "^1.3.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.
I’m fine with adding this since it’s tiny, well-documented, and well-written. But this will need to be in dependencies
if it’s required for runtime! Otherwise it won’t install, and users will get a “module not found” error
@@ -26,8 +27,9 @@ const PATH_PARAM_RE = /\{[^}]+\}/g; | |||
export default function transformPathsObject( | |||
pathsObject: PathsObject, | |||
ctx: GlobalContext, | |||
): ts.TypeNode { | |||
): [ts.TypeNode, ts.TypeAliasDeclaration[]] { |
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.
): [ts.TypeNode, ts.TypeAliasDeclaration[]] { | |
): { node: ts.TypeNode, aliases: ts.TypeAliasDeclaration[] } { |
This is a personal opinion, but let’s not return tuple types for any functions; those don’t scale well. If a function needs to return multiple things, a named object is much better (same for parameters—named objects are more maintainable than ordered params or tuples)
> = { | ||
paths: transformPathsObject, | ||
webhooks: transformWebhooksObject, | ||
components: transformComponentsObject, | ||
$defs: (node, options) => | ||
$defs: (node, options) => [ |
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.
Another tuple type to remove: let’s change this to an interface
instead
Thanks for opening this! This is off to a great start, but we need the following things: Required
I know it’s a lot to ask, but historically, flags have been implemented with gaps, and it’s led to frustration when a feature doesn’t work as expected. I’d like to avoid this for this flag, and release something that works for everyone and not just a limited usecase. And these problems were all reasons the original 1.x moved away from this naming structure. I think we can solve for these now, though, but it will take just a little more planning and a lot more testing |
This PR has gone a while without updates. Closing not as a “won’t accept;” but just to leave room for others to pick up the work if-needed. |
Changes
#1598
Exports component's and path's types from the root:
I reworked the transformers a bit to return an array where the first element is a TypeNode, the second is a list of aliases (TypeAliasDeclaration[]). For each element in the list, a corresponding "friendly name" type will be generated, alongside with
paths
andcomponents
.Additionally, duplicate alias names for components are suffixed with an incremented number using the
renameDuplicates
function.Names and implementation are subject to improve 🙈
But it's an open question which level of nested types for
paths
should be aliased and what is the most convenient way to use them:How to Review
Run
./bin/cli.js
with--root-types
flag.Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)