Something went wrong. Try again.
fork of hey-api/openapi-ts because I need some additional things
Something went wrong. Try again.
930 B · 44 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445import type { IR } from './types';
/** * Simply adds `items` to the schema. Also handles setting the logical operator * and avoids setting it for a single item or tuples. */export function addItemsToSchema({ items, logicalOperator = 'or', mutateSchemaOneItem = false, schema,}: { items: Array<IR.SchemaObject>; logicalOperator?: IR.SchemaObject['logicalOperator']; mutateSchemaOneItem?: boolean; schema: IR.SchemaObject;}): IR.SchemaObject { if (!items.length) { return schema; }
if (schema.type === 'tuple') { schema.items = items; return schema; }
if (items.length !== 1) { schema.items = items; schema.logicalOperator = logicalOperator; return schema; }
if (mutateSchemaOneItem) { // bring composition up to avoid extraneous brackets schema = { ...schema, ...items[0], }; return schema; }
schema.items = items; return schema;}