Skip to content
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

Normalize #2

Open
asherccohen opened this issue Jun 11, 2024 · 0 comments
Open

Normalize #2

asherccohen opened this issue Jun 11, 2024 · 0 comments

Comments

@asherccohen
Copy link
Owner

function normalizeSchema(schema) { const normalizedSchema = Object.keys(schema.properties).reduce((acc, propName) => { const prop = schema.properties[propName]; acc[propName] = { id: propName, type: prop.type, required: schema.required.includes(propName), }; return acc; }, {}); if (schema.if && schema.then && schema.else) { const condition = schema.if.properties; const conditionPropName = Object.keys(condition)[0]; const conditionPropValue = condition[conditionPropName].const; Object.keys(schema.then.properties).forEach((propName) => { normalizedSchema[propName] = { id: propName, type: schema.then.properties[propName].type, required: { condition: { id: conditionPropName, value: conditionPropValue, }, }, }; }); Object.keys(schema.else.properties).forEach((propName) => { normalizedSchema[propName] = { id: propName, type: schema.else.properties[propName].type, required: { condition: { id: conditionPropName, value: !conditionPropValue, }, }, }; }); } if (schema.oneOf) { schema.oneOf.forEach((condition, index) => { Object.keys(condition.properties).forEach((propName) => { normalizedSchema[propName] = { id: propName, type: condition.properties[propName].type, required: { condition: { id: `oneOf_${index}`, value: true, }, }, }; }); }); } return normalizedSchema; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant