Skip to content

Commit

Permalink
Properly translate nested JsonSchema-typed items to ValueSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephVolosin committed Dec 4, 2024
1 parent 7835a15 commit 0631a4d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/utilities/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,29 @@ export function translateJsonSchemaToValueSchema(jsonSchema: SchemaObject | unde
type: JSONType;
};
const propTranslated = translateJsonSchemaTypeToValueSchema(propType as JSONType, propProperties, propItems);
if ('items' in propTranslated) {
propTranslated.items = Object.entries(propTranslated.items).reduce(
(acc: Record<string, ValueSchema>, currentItem: [string, ValueSchema]) => {
const {
type: currentType,
properties: currentProperties,
items: currentItems,
} = currentItem[1] as {
items?: Record<'type', JSONType>;
properties?: Record<string, object>;
type: JSONType;
};
const translatedItem = translateJsonSchemaTypeToValueSchema(
currentType as JSONType,
currentProperties,
currentItems,
);
acc[currentItem[0]] = translatedItem;
return acc;
},
{} as Record<string, ValueSchema>,
);
}
propertiesAsValueSchema[propName] = propTranslated;
} else {
throw new Error('Cannot convert invalid JSON schema property - no "type" field exists');
Expand Down

0 comments on commit 0631a4d

Please sign in to comment.