@mintlify/validation 0.1.395 → 0.1.397

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -813,6 +813,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
813
813
  contextual?: {
814
814
  options: ("copy" | "view" | "chatgpt" | "claude")[];
815
815
  } | undefined;
816
+ thumbnails?: {
817
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
818
+ background?: string | undefined;
819
+ } | undefined;
816
820
  } | {
817
821
  name: string;
818
822
  theme: "aspen";
@@ -1150,6 +1154,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
1150
1154
  contextual?: {
1151
1155
  options: ("copy" | "view" | "chatgpt" | "claude")[];
1152
1156
  } | undefined;
1157
+ thumbnails?: {
1158
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
1159
+ background?: string | undefined;
1160
+ } | undefined;
1153
1161
  } | {
1154
1162
  name: string;
1155
1163
  theme: "linden";
@@ -1487,6 +1495,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
1487
1495
  contextual?: {
1488
1496
  options: ("copy" | "view" | "chatgpt" | "claude")[];
1489
1497
  } | undefined;
1498
+ thumbnails?: {
1499
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
1500
+ background?: string | undefined;
1501
+ } | undefined;
1490
1502
  } | {
1491
1503
  name: string;
1492
1504
  theme: "maple";
@@ -1824,6 +1836,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
1824
1836
  contextual?: {
1825
1837
  options: ("copy" | "view" | "chatgpt" | "claude")[];
1826
1838
  } | undefined;
1839
+ thumbnails?: {
1840
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
1841
+ background?: string | undefined;
1842
+ } | undefined;
1827
1843
  } | {
1828
1844
  name: string;
1829
1845
  theme: "mint";
@@ -2161,6 +2177,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
2161
2177
  contextual?: {
2162
2178
  options: ("copy" | "view" | "chatgpt" | "claude")[];
2163
2179
  } | undefined;
2180
+ thumbnails?: {
2181
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
2182
+ background?: string | undefined;
2183
+ } | undefined;
2164
2184
  } | {
2165
2185
  name: string;
2166
2186
  theme: "palm";
@@ -2498,6 +2518,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
2498
2518
  contextual?: {
2499
2519
  options: ("copy" | "view" | "chatgpt" | "claude")[];
2500
2520
  } | undefined;
2521
+ thumbnails?: {
2522
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
2523
+ background?: string | undefined;
2524
+ } | undefined;
2501
2525
  } | {
2502
2526
  name: string;
2503
2527
  theme: "willow";
@@ -2835,6 +2859,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
2835
2859
  contextual?: {
2836
2860
  options: ("copy" | "view" | "chatgpt" | "claude")[];
2837
2861
  } | undefined;
2862
+ thumbnails?: {
2863
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
2864
+ background?: string | undefined;
2865
+ } | undefined;
2838
2866
  }> | {
2839
2867
  warnings: z.ZodIssue[];
2840
2868
  success: true;
@@ -3175,6 +3203,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
3175
3203
  contextual?: {
3176
3204
  options: ("copy" | "view" | "chatgpt" | "claude")[];
3177
3205
  } | undefined;
3206
+ thumbnails?: {
3207
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
3208
+ background?: string | undefined;
3209
+ } | undefined;
3178
3210
  } | {
3179
3211
  name: string;
3180
3212
  $schema: string;
@@ -3512,6 +3544,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
3512
3544
  contextual?: {
3513
3545
  options: ("copy" | "view" | "chatgpt" | "claude")[];
3514
3546
  } | undefined;
3547
+ thumbnails?: {
3548
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
3549
+ background?: string | undefined;
3550
+ } | undefined;
3515
3551
  } | {
3516
3552
  name: string;
3517
3553
  $schema: string;
@@ -3849,6 +3885,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
3849
3885
  contextual?: {
3850
3886
  options: ("copy" | "view" | "chatgpt" | "claude")[];
3851
3887
  } | undefined;
3888
+ thumbnails?: {
3889
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
3890
+ background?: string | undefined;
3891
+ } | undefined;
3852
3892
  } | {
3853
3893
  name: string;
3854
3894
  $schema: string;
@@ -4186,6 +4226,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
4186
4226
  contextual?: {
4187
4227
  options: ("copy" | "view" | "chatgpt" | "claude")[];
4188
4228
  } | undefined;
4229
+ thumbnails?: {
4230
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
4231
+ background?: string | undefined;
4232
+ } | undefined;
4189
4233
  } | {
4190
4234
  name: string;
4191
4235
  $schema: string;
@@ -4523,6 +4567,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
4523
4567
  contextual?: {
4524
4568
  options: ("copy" | "view" | "chatgpt" | "claude")[];
4525
4569
  } | undefined;
4570
+ thumbnails?: {
4571
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
4572
+ background?: string | undefined;
4573
+ } | undefined;
4526
4574
  } | {
4527
4575
  name: string;
4528
4576
  $schema: string;
@@ -4860,6 +4908,10 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
4860
4908
  contextual?: {
4861
4909
  options: ("copy" | "view" | "chatgpt" | "claude")[];
4862
4910
  } | undefined;
4911
+ thumbnails?: {
4912
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
4913
+ background?: string | undefined;
4914
+ } | undefined;
4863
4915
  } | {
4864
4916
  name: string;
4865
4917
  $schema: string;
@@ -5197,5 +5249,9 @@ export declare function validateDocsConfig(value: unknown): z.SafeParseError<{
5197
5249
  contextual?: {
5198
5250
  options: ("copy" | "view" | "chatgpt" | "claude")[];
5199
5251
  } | undefined;
5252
+ thumbnails?: {
5253
+ appearance?: import("../index.js").ThumbnailAppearance | undefined;
5254
+ background?: string | undefined;
5255
+ } | undefined;
5200
5256
  };
5201
5257
  };
@@ -1,15 +1,5 @@
1
- import { OpenAPIV3_1 } from 'openapi-types';
2
1
  import { IncrementalDataSchemaArray } from './types/endpoint.js';
3
- type Schema3_1 = OpenAPIV3_1.SchemaObject;
4
- type Ref = OpenAPIV3_1.ReferenceObject;
5
- type SchemaOrRef = Schema3_1 | Ref;
6
- type Compositions = 'allOf' | 'oneOf' | 'anyOf' | 'not';
7
- export type SimpleSchema = Omit<OpenAPIV3_1.SchemaObject, Compositions> & {
8
- items?: OpenAPIV3_1.SchemaObject;
9
- refIdentifier?: string;
10
- _depth?: number;
11
- };
12
- export type SumOfProducts = SimpleSchema[][];
2
+ import { SimpleSchema, SchemaOrRef, Schema3_1, SumOfProducts, SchemaOrRefComposition } from './types/schema.js';
13
3
  /**
14
4
  * Given an OpenAPI 3.1 SchemaObject or ReferenceObject containing any number of
15
5
  * refs or compositions, this function returns the schema in sum-of-products form.
@@ -39,7 +29,7 @@ export type SumOfProducts = SimpleSchema[][];
39
29
  * @param componentSchemas The value of `document.components.schemas`, to be used when dereferencing
40
30
  * @returns The schema in sum-of-products form
41
31
  */
42
- export declare function reduceToSumOfProducts(schemaOrRef: SchemaOrRef, componentSchemas: Record<string, Schema3_1> | undefined, opts?: {
32
+ export declare function reduceToSumOfProducts(schemaOrRef: SchemaOrRefComposition, componentSchemas: Record<string, Schema3_1> | undefined, opts?: {
43
33
  isRoot?: true;
44
34
  _depth?: number;
45
35
  }): SumOfProducts;
@@ -60,4 +50,3 @@ export declare function reduceToSumOfProducts(schemaOrRef: SchemaOrRef, componen
60
50
  export declare function combineSimpleSchemas(schemas: SimpleSchema[], componentSchemas: Record<string, Schema3_1> | undefined, location?: 'request' | 'response'): SimpleSchema;
61
51
  export declare function generateFirstIncrementalSchema(schema: SchemaOrRef | undefined, componentSchemas: Record<string, Schema3_1> | undefined, required?: boolean, location?: 'request' | 'response', contentType?: string): IncrementalDataSchemaArray;
62
52
  export declare function generateNextIncrementalSchema(schema: SchemaOrRef, componentSchemas: Record<string, Schema3_1> | undefined, required?: boolean, location?: 'request' | 'response'): IncrementalDataSchemaArray;
63
- export {};
@@ -1,6 +1,5 @@
1
- import lcm from 'lcm';
2
1
  import { inferType } from './SchemaConverter.js';
3
- import { addKeyIfDefined, copyExampleIfDefined, copyKeyIfDefined, dereference, recursivelyFindDescription, stringFileFormats, structuredDataContentTypes, } from './utils.js';
2
+ import { addKeyIfDefined, copyExampleIfDefined, copyKeyIfDefined, dereference, mergeTypes, normalizeMinMax, stringFileFormats, structuredDataContentTypes, sortSchemas, combineExamples, combineProperties, combineDescription, combineAdditionalProperties, copyAndCombineKeys, combineTitle, discriminatorAndSchemaRefsMatch, } from './utils.js';
4
3
  function hasSchemaContent(schema) {
5
4
  const meaningfulKeys = Object.keys(schema).filter((key) => !key.startsWith('_'));
6
5
  return meaningfulKeys.length > 0;
@@ -47,14 +46,17 @@ export function reduceToSumOfProducts(schemaOrRef, componentSchemas, opts) {
47
46
  ((_b = dereferencedSchema.allOf) === null || _b === void 0 ? void 0 : _b.find((subschema) => 'type' in subschema && subschema.type === 'object'))) {
48
47
  dereferencedSchema.type = 'object';
49
48
  }
50
- schema = Object.assign(Object.assign({}, dereferencedSchema), {
51
- // @ts-expect-error some customers use title even though it's not part of the spec
52
- title: (_c = schemaOrRef.title) !== null && _c !== void 0 ? _c : dereferencedSchema.title, refIdentifier: refIdentifier, description: (_d = schemaOrRef.description) !== null && _d !== void 0 ? _d : dereferencedSchema.description });
49
+ // @ts-expect-error some customers use title even though it's not part of the spec
50
+ const dereferencedSchemaTitle = (_c = schemaOrRef.title) !== null && _c !== void 0 ? _c : dereferencedSchema.title;
51
+ schema = Object.assign(Object.assign({}, dereferencedSchema), { title: dereferencedSchemaTitle, refIdentifier: refIdentifier, description: (_d = schemaOrRef.description) !== null && _d !== void 0 ? _d : dereferencedSchema.description, isOneOf: schemaOrRef.isOneOf, isAnyOf: schemaOrRef.isAnyOf, isAllOf: schemaOrRef.isAllOf });
53
52
  }
54
53
  else {
55
54
  schema = schemaOrRef;
56
55
  }
57
- if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && schema.type === 'array' && ((_e = schema.discriminator) === null || _e === void 0 ? void 0 : _e.mapping)) {
56
+ if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) &&
57
+ schema.type === 'array' &&
58
+ ((_e = schema.discriminator) === null || _e === void 0 ? void 0 : _e.mapping) &&
59
+ !discriminatorAndSchemaRefsMatch(schema)) {
58
60
  const discriminator = schema.discriminator;
59
61
  const baseItemSchema = schema.items;
60
62
  delete schema.discriminator;
@@ -90,7 +92,11 @@ export function reduceToSumOfProducts(schemaOrRef, componentSchemas, opts) {
90
92
  });
91
93
  schema = Object.assign(Object.assign({}, schema), { items: Object.assign(Object.assign({}, baseItemSchema), { oneOf: [...processedDiscriminatedTypes, ...extraItems] }) });
92
94
  }
93
- else if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && ((_j = schema.discriminator) === null || _j === void 0 ? void 0 : _j.mapping) && !schema.oneOf && !schema.allOf) {
95
+ else if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) &&
96
+ ((_j = schema.discriminator) === null || _j === void 0 ? void 0 : _j.mapping) &&
97
+ !schema.oneOf &&
98
+ !schema.allOf &&
99
+ !discriminatorAndSchemaRefsMatch(schema)) {
94
100
  const properties = Object.values(schema.discriminator.mapping);
95
101
  if (properties.length) {
96
102
  delete schema.discriminator;
@@ -122,18 +128,36 @@ export function reduceToSumOfProducts(schemaOrRef, componentSchemas, opts) {
122
128
  const baseSchemaArr = hasSchemaContent(baseSchema)
123
129
  ? [baseSchemaTypes.map((type) => [Object.assign(Object.assign({}, baseSchema), { type })])]
124
130
  : [];
125
- const reducedOneOfs = (_k = schema.oneOf) === null || _k === void 0 ? void 0 : _k.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 }));
126
- const reducedAnyOfs = (_l = schema.anyOf) === null || _l === void 0 ? void 0 : _l.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 }));
127
- const reducedAllOfs = (_m = schema.allOf) === null || _m === void 0 ? void 0 : _m.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 }));
131
+ const reducedOneOfs = (_k = schema.oneOf) === null || _k === void 0 ? void 0 : _k.map((subschema) => {
132
+ if ('refIdentifier' in schema) {
133
+ subschema.isOneOf = schema.refIdentifier;
134
+ }
135
+ return reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 });
136
+ });
137
+ const reducedAnyOfs = (_l = schema.anyOf) === null || _l === void 0 ? void 0 : _l.map((subschema) => {
138
+ if ('refIdentifier' in schema) {
139
+ subschema.isAnyOf = schema.refIdentifier;
140
+ }
141
+ return reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 });
142
+ });
143
+ const reducedAllOfs = (_m = schema.allOf) === null || _m === void 0 ? void 0 : _m.map((subschema) => {
144
+ if ('refIdentifier' in schema) {
145
+ subschema.isAllOf = schema.refIdentifier;
146
+ }
147
+ return reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 });
148
+ });
128
149
  const combinedOneOfs = reducedOneOfs ? [addIncrementalSchemas(reducedOneOfs)] : [];
129
150
  const combinedAnyOfs = reducedAnyOfs ? [addIncrementalSchemas(reducedAnyOfs)] : [];
130
151
  const multipliedAllOfs = reducedAllOfs ? [multiplyIncrementalSchemas(reducedAllOfs)] : [];
131
- return multiplyIncrementalSchemas([
152
+ const result = multiplyIncrementalSchemas([
132
153
  ...combinedOneOfs,
133
154
  ...combinedAnyOfs,
134
155
  ...multipliedAllOfs,
135
156
  ...baseSchemaArr,
136
157
  ]);
158
+ // Propagate composition tracking properties to all schemas in the result
159
+ const resultWithCompositionProps = result.map((product) => product.map((schema) => (Object.assign(Object.assign(Object.assign(Object.assign({}, schema), (schema.isOneOf && { isOneOf: schema.isOneOf })), (schema.isAnyOf && { isAnyOf: schema.isAnyOf })), (schema.isAllOf && { isAllOf: schema.isAllOf })))));
160
+ return resultWithCompositionProps;
137
161
  }
138
162
  /**
139
163
  * Adds an array of schemas in sum-of-products form, returning the result
@@ -163,7 +187,36 @@ function multiplyIncrementalSchemas(schemas) {
163
187
  // in our scenario, the remaining terms are (E + F)(G + H), which gives us (EG + EH + FG + FH)
164
188
  const remainingSumOfProducts = multiplyIncrementalSchemas(schemas.slice(1));
165
189
  return schemas[0].flatMap((product /* AB */) => {
166
- return remainingSumOfProducts.map((remainingProduct /* EF */) => [...product, ...remainingProduct] /* ABEF */);
190
+ return remainingSumOfProducts.map((remainingProduct /* EF */) => {
191
+ // Combine all schemas in the product
192
+ const combinedProduct = [...product, ...remainingProduct];
193
+ // Propagate composition tracking properties from all schemas to each schema
194
+ return combinedProduct.map((schema) => {
195
+ const compositionProps = {};
196
+ // Collect all composition properties from all schemas in the product
197
+ combinedProduct.forEach((otherSchema) => {
198
+ if (otherSchema.isOneOf)
199
+ compositionProps.isOneOf = otherSchema.isOneOf;
200
+ if (otherSchema.isAnyOf)
201
+ compositionProps.isAnyOf = otherSchema.isAnyOf;
202
+ if (otherSchema.isAllOf)
203
+ compositionProps.isAllOf = otherSchema.isAllOf;
204
+ });
205
+ // Filter out composition properties that match refIdentifier
206
+ if (schema.refIdentifier) {
207
+ if (compositionProps.isOneOf === schema.refIdentifier) {
208
+ delete compositionProps.isOneOf;
209
+ }
210
+ if (compositionProps.isAnyOf === schema.refIdentifier) {
211
+ delete compositionProps.isAnyOf;
212
+ }
213
+ if (compositionProps.isAllOf === schema.refIdentifier) {
214
+ delete compositionProps.isAllOf;
215
+ }
216
+ }
217
+ return Object.assign(Object.assign({}, schema), compositionProps);
218
+ });
219
+ });
167
220
  });
168
221
  }
169
222
  /**
@@ -181,183 +234,27 @@ function multiplyIncrementalSchemas(schemas) {
181
234
  * @returns A single simple schema that satisfies all the input schemas
182
235
  */
183
236
  export function combineSimpleSchemas(schemas, componentSchemas, location) {
184
- // all schemas with no `type` field go at the end of the array to avoid
185
- // caling `copyKeyIfDefined` for discriminators with empty types unless
186
- // we're certain the schema's title is the last possible option
187
- schemas.sort((a, b) => {
188
- var _a, _b;
189
- const aDepth = (_a = a._depth) !== null && _a !== void 0 ? _a : 0;
190
- const bDepth = (_b = b._depth) !== null && _b !== void 0 ? _b : 0;
191
- if (aDepth !== bDepth) {
192
- return aDepth - bDepth;
193
- }
194
- if (a.type && !b.type)
195
- return -1;
196
- if (!a.type && b.type)
197
- return 1;
198
- return 0;
199
- });
237
+ sortSchemas(schemas);
200
238
  return schemas.reduce((acc, curr) => {
201
- var _a, _b, _c, _d, _e, _f;
202
- // schemas are meant to be immutable, so copy the type
203
- let currType = curr.type;
204
- // don't throw an error if type is being constricted
205
- if (acc.type === 'integer' && currType === 'number') {
206
- currType = 'integer';
207
- }
208
- else if (acc.type === 'number' && currType === 'integer') {
209
- acc.type = 'integer';
210
- }
211
- else if (acc.type === undefined && currType !== undefined) {
212
- acc.type = currType;
213
- }
214
- else if (acc.type !== undefined && currType === undefined) {
215
- currType = acc.type;
216
- }
217
- if (acc.type !== currType) {
218
- throw new Error(`${acc.type} vs ${currType}`);
219
- }
220
- // we're technically breaking immutability rules here, but it's probably okay because
221
- // it will be the same every time - we're just normalizing the maximum/minimum
222
- // and exclusiveMaximum/exclusiveMinimum properties
239
+ var _a;
240
+ mergeTypes(acc, curr);
223
241
  for (const schema of [acc, curr]) {
224
- if (typeof schema.exclusiveMaximum === 'number') {
225
- if (schema.maximum === undefined || schema.maximum >= schema.exclusiveMaximum) {
226
- schema.maximum = schema.exclusiveMaximum;
227
- schema.exclusiveMaximum = true;
228
- }
229
- else {
230
- schema.exclusiveMaximum = undefined;
231
- }
232
- }
233
- if (typeof schema.exclusiveMinimum === 'number') {
234
- if (schema.minimum === undefined || schema.minimum <= schema.exclusiveMinimum) {
235
- schema.minimum = schema.exclusiveMinimum;
236
- schema.exclusiveMinimum = true;
237
- }
238
- else {
239
- schema.exclusiveMinimum = undefined;
240
- }
241
- }
242
- }
243
- if (curr.discriminator == undefined && (curr.type != undefined || acc.title == undefined)) {
244
- copyKeyIfDefined('title', curr, acc);
245
- }
246
- copyKeyIfDefined('refIdentifier', curr, acc);
247
- copyKeyIfDefined('examples', curr, acc);
248
- copyKeyIfDefined('format', curr, acc);
249
- copyKeyIfDefined('default', curr, acc);
250
- copyKeyIfDefined('x-default', curr, acc);
251
- copyKeyIfDefined('const', curr, acc);
252
- combineKeyIfDefined('multipleOf', curr, acc, lcm);
253
- combineKeyIfDefined('maxLength', curr, acc, Math.min);
254
- combineKeyIfDefined('minLength', curr, acc, Math.max);
255
- combineKeyIfDefined('maxItems', curr, acc, Math.min);
256
- combineKeyIfDefined('minItems', curr, acc, Math.max);
257
- combineKeyIfDefined('maxProperties', curr, acc, Math.min);
258
- combineKeyIfDefined('minProperties', curr, acc, Math.max);
259
- combineKeyIfDefined('required', curr, acc, (a, b) => b.concat(a.filter((value) => !b.includes(value))));
260
- combineKeyIfDefined('enum', curr, acc, (a, b) => b.filter((value) => a.includes(value)));
261
- combineKeyIfDefined('readOnly', curr, acc, (a, b) => a && b);
262
- combineKeyIfDefined('writeOnly', curr, acc, (a, b) => a && b);
263
- combineKeyIfDefined('deprecated', curr, acc, (a, b) => a || b);
264
- const combinedMaximum = combine(curr, acc, 'maximum', Math.min);
265
- const combinedMinimum = combine(curr, acc, 'minimum', Math.max);
266
- const exclusiveMaximum = (acc.maximum === combinedMaximum ? acc.exclusiveMaximum : undefined) ||
267
- (curr.maximum === combinedMaximum ? curr.exclusiveMaximum : undefined);
268
- addKeyIfDefined('exclusiveMaximum', exclusiveMaximum, acc);
269
- const exclusiveMinimum = (acc.minimum === combinedMinimum ? acc.exclusiveMinimum : undefined) ||
270
- (curr.minimum === combinedMinimum ? curr.exclusiveMinimum : undefined);
271
- addKeyIfDefined('exclusiveMinimum', exclusiveMinimum, acc);
272
- addKeyIfDefined('maximum', combinedMaximum, acc);
273
- addKeyIfDefined('minimum', combinedMinimum, acc);
274
- // don't use coalesce operator, since null is a valid example
275
- const example1 = ((_a = acc.examples) === null || _a === void 0 ? void 0 : _a[0]) !== undefined ? acc.examples[0] : acc.example;
276
- const example2 = ((_b = curr.examples) === null || _b === void 0 ? void 0 : _b[0]) !== undefined ? curr.examples[0] : curr.example;
277
- if (example1 && example2 && typeof example1 === 'object' && typeof example2 === 'object') {
278
- acc.example = Object.assign(Object.assign({}, example1), example2);
279
- }
280
- else {
281
- // don't use coalesce operator, since null is a valid example
282
- addKeyIfDefined('example', example2 !== undefined ? example2 : example1, acc);
242
+ normalizeMinMax(schema);
283
243
  }
244
+ combineTitle(acc, curr);
245
+ copyAndCombineKeys(acc, curr);
246
+ combineExamples(acc, curr);
284
247
  if (curr.items) {
285
- const items = (_c = acc.items) !== null && _c !== void 0 ? _c : { allOf: [] };
248
+ const items = (_a = acc.items) !== null && _a !== void 0 ? _a : { allOf: [] };
286
249
  items.allOf.push(curr.items);
287
250
  acc.items = items;
288
251
  }
289
- if (curr.properties) {
290
- Object.entries(curr.properties)
291
- .filter(([_, subschema]) => {
292
- // dereference just for the readOnly/writeOnly check
293
- if ('$ref' in subschema) {
294
- const dereferencedSchema = dereference('schemas', subschema.$ref, componentSchemas);
295
- if (!dereferencedSchema)
296
- return true;
297
- subschema = dereferencedSchema;
298
- }
299
- if (subschema.readOnly && location === 'request')
300
- return false;
301
- if (subschema.writeOnly && location === 'response')
302
- return false;
303
- return true;
304
- })
305
- .forEach(([property, subschema]) => {
306
- var _a;
307
- const properties = (_a = acc.properties) !== null && _a !== void 0 ? _a : {};
308
- const currSchemaArr = properties[property];
309
- if (currSchemaArr) {
310
- currSchemaArr.allOf.push(subschema);
311
- }
312
- else {
313
- properties[property] = { allOf: [subschema] };
314
- }
315
- acc.properties = properties;
316
- });
317
- }
318
- if (((_d = acc.properties) === null || _d === void 0 ? void 0 : _d.type) && curr.discriminator && !acc.description) {
319
- let name = undefined;
320
- const allOf = (_e = acc.properties.type.allOf[0]) !== null && _e !== void 0 ? _e : {};
321
- if ('const' in allOf && typeof allOf.const === 'string') {
322
- name = allOf.const;
323
- }
324
- const description = recursivelyFindDescription(curr, name) ||
325
- schemas.flatMap((schema) => recursivelyFindDescription(schema, name)).filter(Boolean)[0];
326
- if (description) {
327
- acc.description = description;
328
- }
329
- }
330
- else if (acc.description &&
331
- curr.description &&
332
- !curr.discriminator &&
333
- !acc.description.includes(curr.description)) {
334
- acc.description = `${acc.description}\n${curr.description}`;
335
- }
336
- else if (!acc.description) {
337
- copyKeyIfDefined('description', curr, acc);
338
- }
339
- if (curr.additionalProperties === false) {
340
- acc.additionalProperties = false;
341
- }
342
- else if (acc.additionalProperties !== false &&
343
- curr.additionalProperties &&
344
- typeof curr.additionalProperties === 'object') {
345
- const additionalProperties = (_f = acc.additionalProperties) !== null && _f !== void 0 ? _f : { allOf: [] };
346
- additionalProperties.allOf.push(curr.additionalProperties);
347
- acc.additionalProperties = additionalProperties;
348
- }
252
+ combineProperties(acc, curr, componentSchemas, location);
253
+ combineDescription(acc, curr, schemas);
254
+ combineAdditionalProperties(acc, curr);
349
255
  return acc;
350
256
  }, {});
351
257
  }
352
- const combineKeyIfDefined = (key, source, destination, transform) => {
353
- addKeyIfDefined(key, combine(source, destination, key, transform), destination);
354
- };
355
- const combine = (schema1, schema2, key, transform) => {
356
- var _a;
357
- return schema1[key] !== undefined && schema2[key] !== undefined
358
- ? transform(schema1[key], schema2[key])
359
- : (_a = schema1[key]) !== null && _a !== void 0 ? _a : schema2[key];
360
- };
361
258
  function convertCombinedSchema(schema, required) {
362
259
  var _a, _b;
363
260
  const sharedProps = {};
@@ -120,6 +120,9 @@ export type BaseSchema<T> = {
120
120
  writeOnly?: boolean;
121
121
  deprecated?: boolean;
122
122
  refIdentifier?: string;
123
+ isOneOf?: string;
124
+ isAnyOf?: string;
125
+ isAllOf?: string;
123
126
  };
124
127
  export type BooleanSchema = {
125
128
  type: 'boolean';
@@ -0,0 +1,31 @@
1
+ import { OpenAPIV3_1 } from 'openapi-types';
2
+ export type Schema3_1 = OpenAPIV3_1.SchemaObject;
3
+ export type Ref = OpenAPIV3_1.ReferenceObject;
4
+ export type SchemaOrRef = Schema3_1 | Ref;
5
+ export type ComponentsSection = keyof OpenAPIV3_1.ComponentsObject;
6
+ export type Compositions = 'allOf' | 'oneOf' | 'anyOf' | 'not';
7
+ export type SimpleSchema = Omit<OpenAPIV3_1.SchemaObject, Compositions> & {
8
+ items?: OpenAPIV3_1.SchemaObject;
9
+ refIdentifier?: string;
10
+ _depth?: number;
11
+ isOneOf?: string;
12
+ isAnyOf?: string;
13
+ isAllOf?: string;
14
+ };
15
+ export type SumOfProducts = SimpleSchema[][];
16
+ export type SimpleSchemaWithSubschemas = SimpleSchema & {
17
+ properties?: Record<string, {
18
+ allOf: SchemaOrRef[];
19
+ }>;
20
+ items?: {
21
+ allOf: SchemaOrRef[];
22
+ };
23
+ additionalProperties?: {
24
+ allOf: SchemaOrRef[];
25
+ } | false;
26
+ };
27
+ export type SchemaOrRefComposition = SchemaOrRef & {
28
+ isOneOf?: string;
29
+ isAnyOf?: string;
30
+ isAllOf?: string;
31
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,12 +1,20 @@
1
1
  import { OpenAPIV3_1 } from 'openapi-types';
2
- import { SimpleSchema } from './IncrementalEvaluator.js';
3
2
  import { DataSchema } from './types/endpoint.js';
3
+ import { ComponentsSection, Schema3_1, SimpleSchema, SimpleSchemaWithSubschemas } from './types/schema.js';
4
4
  export declare const stringFileFormats: string[];
5
5
  export declare const structuredDataContentTypes: string[];
6
- type ComponentsSection = keyof OpenAPIV3_1.ComponentsObject;
7
6
  export declare function dereference<S extends ComponentsSection>(section: S, $ref: string, components: Record<string, NonNullable<OpenAPIV3_1.ComponentsObject[S]>[string]> | undefined, maxDepth?: number): NonNullable<OpenAPIV3_1.ComponentsObject[S]>[string] | undefined;
8
7
  export declare const addKeyIfDefined: <D, K extends keyof D>(key: K, value: D[K] | undefined, destination: D) => void;
9
8
  export declare const copyKeyIfDefined: <D, K extends keyof D>(key: K, source: Pick<D, K>, destination: D) => void;
10
9
  export declare const copyExampleIfDefined: (source: Pick<OpenAPIV3_1.SchemaObject, "example" | "examples">, destination: Pick<DataSchema, "example">) => void;
11
10
  export declare function recursivelyFindDescription(schema: SimpleSchema, name: string | undefined): string | undefined;
12
- export {};
11
+ export declare function sortSchemas(schemas: SimpleSchema[]): void;
12
+ export declare function mergeTypes(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema): void;
13
+ export declare function normalizeMinMax(schema: SimpleSchema): void;
14
+ export declare function combineTitle(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema): void;
15
+ export declare function copyAndCombineKeys(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema): void;
16
+ export declare function combineExamples(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema): void;
17
+ export declare function combineProperties(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema, componentSchemas: Record<string, Schema3_1> | undefined, location?: 'request' | 'response'): void;
18
+ export declare function combineDescription(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema, schemas: SimpleSchema[]): void;
19
+ export declare function combineAdditionalProperties(acc: SimpleSchemaWithSubschemas, curr: SimpleSchema): void;
20
+ export declare function discriminatorAndSchemaRefsMatch(schema: SimpleSchema): boolean;