Skip to content

Commit

Permalink
ensure correct eval of required properties with allOf (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
sserrata authored Mar 22, 2024
1 parent 4bb7040 commit 82d1e1a
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export function mergeAllOf(allOf: SchemaObject[]) {
ignoreAdditionalProperties: true,
});

const required = allOf.reduce((acc, cur) => {
const mergedRequired = allOf.reduce((acc, cur) => {
if (Array.isArray(cur.required)) {
const next = [...acc, ...cur.required];
return next;
}
return acc;
}, [] as any);

return { mergedSchemas, required };
return { mergedSchemas, mergedRequired };
}

/**
Expand Down Expand Up @@ -260,9 +260,8 @@ function createItems(schema: SchemaObject) {
// TODO: figure out if and how we should pass merged required array
const {
mergedSchemas,
}: { mergedSchemas: SchemaObject; required: string[] } = mergeAllOf(
schema.items?.allOf
);
}: { mergedSchemas: SchemaObject; mergedRequired: string[] | boolean } =
mergeAllOf(schema.items?.allOf);

// Handles combo anyOf/oneOf + properties
if (
Expand Down Expand Up @@ -596,7 +595,6 @@ function createEdges({
discriminator,
}: EdgeProps): any {
const schemaName = getSchemaName(schema);

if (discriminator !== undefined && discriminator.propertyName === name) {
return createPropertyDiscriminator(
name,
Expand All @@ -618,11 +616,9 @@ function createEdges({
}

if (schema.allOf !== undefined) {
const {
mergedSchemas,
required,
}: { mergedSchemas: SchemaObject; required: string[] | boolean } =
mergeAllOf(schema.allOf);
const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
schema.allOf
);
const mergedSchemaName = getSchemaName(mergedSchemas);
if (
mergedSchemas.oneOf !== undefined ||
Expand Down

0 comments on commit 82d1e1a

Please sign in to comment.