-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
Skip Schema prefix trimmin if --enum is used with --root-types-no-schema-prefix #2206
base: main
Are you sure you want to change the base?
Skip Schema prefix trimmin if --enum is used with --root-types-no-schema-prefix #2206
Conversation
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
|
ba8e5ef
to
31054dc
Compare
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.
Nice! Some comments about behavior / comments. The code itself looks great!
Thanks for taking a look at this, I will address your comments. |
91394c2
to
cf6d0a1
Compare
cf6d0a1
to
3392361
Compare
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.
Thanks for taking the time to fix this @sultaniman!
Please see my suggestion
// Skipping --root-types generation only for enums if --enum is set | ||
// while still applying --root-types-no-schema-prefix to other types. | ||
if (!(ctx.enum && item.enum !== undefined)) { | ||
aliasName = aliasName.replace(componentKey, ""); | ||
} |
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.
@sultaniman While this fixes the issue, it introduces an inconsistency in the generated types. Everything else will have the Schema prefix removed, but for enums, we’ll end up with both EnumName
(the enum itself) and an unnecessary SchemaEnumName
.
Since EnumName
already serves as both a value and a TypeScript type due to the nature of enums, SchemaEnumName
seems redundant. Wouldn't it make more sense to omit the root type for enums entirely when --root-types-no-schema-prefix
is used? (That was my suggestion in the original PR.)
Changes
This PR is a follow up to #1958 and as a result disables
--root-types-no-schema-prefix
when--enum
flag passed.More on why this is necessary: #1958 (comment)
How to Review
Check out the mentioned PR and review this one.
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)