fork of hey-api/openapi-ts because I need some additional things
1import type { IR } from './types';
2
3/**
4 * Simply adds `items` to the schema. Also handles setting the logical operator
5 * and avoids setting it for a single item or tuples.
6 */
7export function addItemsToSchema({
8 items,
9 logicalOperator = 'or',
10 mutateSchemaOneItem = false,
11 schema,
12}: {
13 items: Array<IR.SchemaObject>;
14 logicalOperator?: IR.SchemaObject['logicalOperator'];
15 mutateSchemaOneItem?: boolean;
16 schema: IR.SchemaObject;
17}): IR.SchemaObject {
18 if (!items.length) {
19 return schema;
20 }
21
22 if (schema.type === 'tuple') {
23 schema.items = items;
24 return schema;
25 }
26
27 if (items.length !== 1) {
28 schema.items = items;
29 schema.logicalOperator = logicalOperator;
30 return schema;
31 }
32
33 if (mutateSchemaOneItem) {
34 // bring composition up to avoid extraneous brackets
35 schema = {
36 ...schema,
37 ...items[0],
38 };
39 return schema;
40 }
41
42 schema.items = items;
43 return schema;
44}