-
-
Notifications
You must be signed in to change notification settings - Fork 528
Improve handling of oneOf and enum #1236
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: 45a79cb 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 |
Deploying with
|
Latest commit: |
45a79cb
|
Status: | ✅ Deploy successful! |
Preview URL: | https://92639452.openapi-ts.pages.dev |
Branch Preview URL: | https://oneof-enum.openapi-ts.pages.dev |
@@ -13321,7 +13323,7 @@ export interface components { | |||
* Organization ruleset conditions | |||
* @description Conditions for an organization ruleset | |||
*/ | |||
"org-ruleset-conditions": (components["schemas"]["repository-ruleset-conditions"] & components["schemas"]["repository-ruleset-conditions-repository-name-target"]) | (components["schemas"]["repository-ruleset-conditions"] & components["schemas"]["repository-ruleset-conditions-repository-id-target"]); | |||
"org-ruleset-conditions": Record<string, never> & ((components["schemas"]["repository-ruleset-conditions"] & components["schemas"]["repository-ruleset-conditions-repository-name-target"]) | (components["schemas"]["repository-ruleset-conditions"] & components["schemas"]["repository-ruleset-conditions-repository-id-target"])); |
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.
Fortunately the Record<string, never>
doesn’t interfere with the type at all; it’s just an empty object that gets ignored
@@ -90333,15 +90335,97 @@ export interface operations { | |||
}; | |||
requestBody: { | |||
content: { | |||
"application/json": OneOf<[{ | |||
"application/json": ({ |
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.
This is a big improvement, and a scenario where maybe we should start preferring practice over theory
@@ -447,18 +447,21 @@ export type SchemaObject = { | |||
|
|||
export interface StringSubtype { | |||
type: "string"; | |||
enum?: (string | ReferenceObject)[]; |
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 not completely happy with the enum
type changes; we may need to change these in the future. But it just made this change easier.
Changes
Before, if
oneOf
orenum
was present, we ignored the core type (for objects, at least). In this PR, we now create an intersection of the core type +oneOf
/enum
.The reason for the
enum
handling was although unconventional, I did find usage of it in the GitHub API schemas. And I couldn’t find any explicit signal that this is invalid. So just for object types, we’ll treatenum == oneOf
.How to Review
Tests should pass.
Checklist
examples/
directory updated (only applicable for openapi-typescript)