Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseSchemaLike(c: SchemaLike, modelsToParse: Array): O3TS.SchemaObject | O3TS.ReferenceObject {
// It's important to note that this method DOES have a side effect: it
// adds any found models to `modelsToParse`.
if (typeof(c) === 'function') {
return inferSchema(c, modelsToParse);
} else if (Array.isArray(c)) {
return { type: 'array', items: parseSchemaLike(c[0], modelsToParse) };
} else if (isReferenceObject(c)) {
return c;
} else { // O3TS.SchemaObjects, but potentially with deeper schemaLikes.
const ret: O3TS.SchemaObject = {
...c,
};
if (c.allOf) {
ret.allOf = c.allOf.map(sub => parseSchemaLike(sub, modelsToParse));
}
if (c.anyOf) {
ret.anyOf = c.anyOf.map(sub => parseSchemaLike(sub, modelsToParse));
}
if (c.oneOf) {
ret.oneOf = c.oneOf.map(sub => parseSchemaLike(sub, modelsToParse));