-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
Fix discriminator propertyName inference #1342
Conversation
🦋 Changeset detectedLatest commit: 8169953 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 Cloudflare Pages
|
// core type: properties + additionalProperties | ||
const coreType: string[] = []; | ||
|
||
// discriminators | ||
for (const k of ["oneOf", "allOf", "anyOf"] as ("oneOf" | "allOf" | "anyOf")[]) { |
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.
Note: this was moved up before property generation due to the change in automatic discriminator.propertyName
possibly adding keys to the object. We can’t detect if there may be a key conflict, but we can let the explicit properties override it if they come afterward.
if (Array.isArray(node.oneOf)) { | ||
for (const child of node.oneOf) { | ||
if (!child || typeof child !== "object" || !("$ref" in child)) continue; | ||
oneOf.push(child.$ref); |
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 adds automatic inference from parent oneOf
types, but unfortunately the mapping is brittle (probably breaks for remote schemas).
I think the only way to fix this is if this library pre-bundled schemas via something like Redocly bundle
Changes
Fixes an issue where
propertyName
wasn’t automatically generated fordiscriminators
(mappings are not required; they only are needed to override the automatic inference).Related to #1158 and #1116
How to Review
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)