Skip to content

Handle case where propertyName not defined in schemas and/or 0-length mapping #1044

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ const DiscriminatorNode: React.FC<DiscriminatorNodeProps> = ({

// default to empty object if no parent-level properties exist
const discriminatorProperty = schema.properties
? schema.properties![discriminator.propertyName]
? (schema.properties![discriminator.propertyName] ?? {})
: {};

if (schema.allOf) {
Expand All @@ -341,6 +341,12 @@ const DiscriminatorNode: React.FC<DiscriminatorNodeProps> = ({
discriminator.mapping = inferredMapping;
}

// handle invalid discriminator definition where no discriminated schemas are defined
if (Object.keys(discriminator.mapping).length === 0) {
delete schema.discriminator;
return <SchemaNode schema={schema} schemaType={schemaType} />;
}

// Merge sub schema discriminator property with parent
Object.keys(discriminator.mapping).forEach((key) => {
const subSchema = discriminator.mapping[key];
Expand Down
Loading