@mintlify/validation 0.1.57 → 0.1.59

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.
Files changed (32) hide show
  1. package/dist/index.js +86 -2
  2. package/dist/mint-config/common.js +12 -0
  3. package/dist/mint-config/flattenUnionErrorMessages.js +23 -0
  4. package/dist/mint-config/hexadecimalPattern.js +4 -0
  5. package/dist/mint-config/schemas/analytics.js +132 -0
  6. package/dist/mint-config/schemas/anchorColors.js +31 -0
  7. package/dist/mint-config/schemas/anchors.d.ts +6 -6
  8. package/dist/mint-config/schemas/anchors.js +72 -0
  9. package/dist/mint-config/schemas/apiReference.js +68 -0
  10. package/dist/mint-config/schemas/basics.js +135 -0
  11. package/dist/mint-config/schemas/colors.js +45 -0
  12. package/dist/mint-config/schemas/config.d.ts +13 -13
  13. package/dist/mint-config/schemas/config.js +42 -0
  14. package/dist/mint-config/schemas/favicon.js +12 -0
  15. package/dist/mint-config/schemas/integrations.js +14 -0
  16. package/dist/mint-config/schemas/navigation.js +27 -0
  17. package/dist/mint-config/schemas/tabs.js +31 -0
  18. package/dist/mint-config/schemas/versions.js +16 -0
  19. package/dist/mint-config/types/enums.js +4 -0
  20. package/dist/mint-config/types/index.js +2 -0
  21. package/dist/mint-config/types/navigation.js +2 -0
  22. package/dist/mint-config/validateAnchorsWarnings.js +39 -0
  23. package/dist/mint-config/validateVersionsInNavigation.js +60 -0
  24. package/dist/openapi/convertOpenApi.js +174 -0
  25. package/dist/openapi/convertParameters.js +64 -0
  26. package/dist/openapi/convertSchema.js +486 -0
  27. package/dist/openapi/convertSecurity.js +87 -0
  28. package/dist/openapi/convertServers.js +47 -0
  29. package/dist/openapi/types/endpoint.js +16 -0
  30. package/dist/tsconfig.build.tsbuildinfo +1 -0
  31. package/package.json +7 -4
  32. package/dist/index.js.LICENSE.txt +0 -8
@@ -0,0 +1,486 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.convertProperties = exports.copyKeyIfDefined = exports.addKeyIfDefined = exports.combineTopLevelSchemas = exports.convertSchema = void 0;
27
+ var lcm_1 = __importDefault(require("lcm"));
28
+ var lodash_1 = __importDefault(require("lodash"));
29
+ var convertOpenApi_1 = require("./convertOpenApi");
30
+ var endpoint_1 = require("./types/endpoint");
31
+ var convertSchema = function (path, schema, required) {
32
+ if (schema === undefined) {
33
+ throw new convertOpenApi_1.InvalidSchemaError(path, 'schema undefined');
34
+ }
35
+ // TODO(ronan): remove when fully migrated to endpoint type, or don't modify schema in evaluateCompositionsRecursive
36
+ schema = lodash_1.default.cloneDeep(schema);
37
+ schema = evaluateCompositionsRecursive(path, schema);
38
+ return convertSchemaRecursive(path, schema, required);
39
+ };
40
+ exports.convertSchema = convertSchema;
41
+ /**
42
+ * This function should be used to reduce strictly `oneOf` and `anyOf` compositions.
43
+ *
44
+ * @param schemaArray `schema.allOf` or `schema.oneOf`
45
+ * @returns a schema array equivalent to the `schemaArray` argument, but in reduced form
46
+ */
47
+ var evaluateOptionsCompositions = function (path, schemaArray) {
48
+ var evaluatedArray = schemaArray.flatMap(function (subschema, i) {
49
+ var _a;
50
+ try {
51
+ return (_a = evaluateCompositionsRecursive(__spreadArray(__spreadArray([], path, true), [i.toString()], false), subschema).oneOf) !== null && _a !== void 0 ? _a : [];
52
+ }
53
+ catch (error) {
54
+ if (error instanceof convertOpenApi_1.ImpossibleSchemaError) {
55
+ return [];
56
+ }
57
+ else {
58
+ throw error;
59
+ }
60
+ }
61
+ });
62
+ if (evaluatedArray.length === 0) {
63
+ throw new convertOpenApi_1.ImpossibleSchemaError(path, 'no valid options in schema:', JSON.stringify(schemaArray, undefined, 2));
64
+ }
65
+ return evaluatedArray;
66
+ };
67
+ var evaluateCompositionsRecursive = function (path, schema) {
68
+ // evaluate compositions first; we are currently ignoring `not`
69
+ if (schema.oneOf && schema.oneOf.length > 0) {
70
+ schema.oneOf = evaluateOptionsCompositions(__spreadArray(__spreadArray([], path, true), ['oneOf'], false), schema.oneOf);
71
+ }
72
+ else {
73
+ schema.oneOf = [];
74
+ }
75
+ if (schema.anyOf && schema.anyOf.length > 0) {
76
+ schema.anyOf = evaluateOptionsCompositions(__spreadArray(__spreadArray([], path, true), ['anyOf'], false), schema.anyOf);
77
+ }
78
+ if (schema.allOf && schema.allOf.length > 0) {
79
+ var totalAllOfObj = schema.allOf
80
+ .map(function (subschema, i) {
81
+ return evaluateCompositionsRecursive(__spreadArray(__spreadArray([], path, true), ['allOf', i.toString()], false), subschema);
82
+ })
83
+ .reduce(function (schema1, schema2, i) {
84
+ return combineReducedSchemas(__spreadArray(__spreadArray([], path, true), ['allOf', i.toString()], false), schema1, schema2);
85
+ }, {
86
+ oneOf: [],
87
+ });
88
+ schema.oneOf = multiplySchemaArrays(path, schema.oneOf, totalAllOfObj.oneOf);
89
+ }
90
+ // evaluate subschemas, if present
91
+ if (schema.properties) {
92
+ for (var key in schema.properties) {
93
+ schema.properties[key] = evaluateCompositionsRecursive(__spreadArray(__spreadArray([], path, true), ['properties', key], false), schema.properties[key]);
94
+ }
95
+ }
96
+ if (schema.items) {
97
+ schema.items = evaluateCompositionsRecursive(__spreadArray(__spreadArray([], path, true), ['items'], false), schema.items);
98
+ }
99
+ if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
100
+ try {
101
+ schema.additionalProperties = evaluateCompositionsRecursive(__spreadArray(__spreadArray([], path, true), ['additionalProperties'], false), schema.additionalProperties);
102
+ }
103
+ catch (error) {
104
+ if (error instanceof convertOpenApi_1.ImpossibleSchemaError) {
105
+ // if additionalProperties schema is impossible, rather than error, just disallow additionalProperties
106
+ schema.additionalProperties = false;
107
+ }
108
+ else {
109
+ throw error;
110
+ }
111
+ }
112
+ }
113
+ if (schema.anyOf && schema.anyOf.length > 0) {
114
+ schema.oneOf = multiplySchemaArrays(path, schema.oneOf, schema.anyOf);
115
+ }
116
+ var topLevelSchemaArray = generateTopLevelSchemaArray(schema);
117
+ return { oneOf: multiplySchemaArrays(path, schema.oneOf, topLevelSchemaArray) };
118
+ };
119
+ var generateTopLevelSchemaArray = function (schema) {
120
+ if (schema.nullable) {
121
+ var typedSchema = __assign({}, schema);
122
+ delete typedSchema.oneOf;
123
+ delete typedSchema.nullable;
124
+ var nullSchema = __assign({}, schema);
125
+ delete nullSchema.oneOf;
126
+ delete nullSchema.nullable;
127
+ nullSchema.type = 'null';
128
+ return [typedSchema, nullSchema];
129
+ }
130
+ if (Array.isArray(schema.type)) {
131
+ if (schema.type.length === 0) {
132
+ var topLevelSchema_1 = __assign({}, schema);
133
+ delete topLevelSchema_1.oneOf;
134
+ delete topLevelSchema_1.type;
135
+ return [topLevelSchema_1];
136
+ }
137
+ return schema.type.map(function (typeString) {
138
+ var topLevelSchema = __assign({}, schema);
139
+ delete topLevelSchema.oneOf;
140
+ topLevelSchema.type = typeString;
141
+ return topLevelSchema;
142
+ });
143
+ }
144
+ var topLevelSchema = __assign({}, schema);
145
+ delete topLevelSchema.oneOf;
146
+ return [topLevelSchema];
147
+ };
148
+ /**
149
+ * Given two arrays representing schema options, return an array representing schema options that satisfy one element in both arrays.
150
+ *
151
+ * It is helpful to think of each array as a union of all the schemas in the array. This function can then be thought of as taking
152
+ * the intersection of the two union types.
153
+ *
154
+ * @param a first array of schema options
155
+ * @param b second array of schema options
156
+ * @returns array of schemas that satisfy both arrays
157
+ */
158
+ var multiplySchemaArrays = function (path, a, b) {
159
+ if (a.length === 0 && b.length === 0) {
160
+ return [{}];
161
+ }
162
+ if (a.length === 0) {
163
+ return b;
164
+ }
165
+ if (b.length === 0) {
166
+ return a;
167
+ }
168
+ var product = a.flatMap(function (schema1) {
169
+ return b.flatMap(function (schema2) {
170
+ try {
171
+ var combinedSchema = (0, exports.combineTopLevelSchemas)(path, schema1, schema2);
172
+ return [combinedSchema];
173
+ }
174
+ catch (error) {
175
+ if (error instanceof convertOpenApi_1.ImpossibleSchemaError) {
176
+ return [];
177
+ }
178
+ else {
179
+ throw error;
180
+ }
181
+ }
182
+ });
183
+ });
184
+ if (product.length === 0) {
185
+ throw new convertOpenApi_1.ImpossibleSchemaError(path, 'impossible schema combination:', 'schema array 1:', JSON.stringify(a, undefined, 2), 'schema array 2:', JSON.stringify(b, undefined, 2));
186
+ }
187
+ return product;
188
+ };
189
+ var combineReducedSchemas = function (path, schema1, schema2) {
190
+ var _a, _b;
191
+ return {
192
+ oneOf: multiplySchemaArrays(path, ((_a = schema1.oneOf) !== null && _a !== void 0 ? _a : []), ((_b = schema2.oneOf) !== null && _b !== void 0 ? _b : [])),
193
+ };
194
+ };
195
+ var combineTopLevelSchemas = function (path, schema1, schema2) {
196
+ var _a, _b;
197
+ var type1 = schema1.type;
198
+ var type2 = schema2.type;
199
+ // don't throw an error if number type is being constricted
200
+ if (type1 === 'integer' && type2 === 'number') {
201
+ type2 = 'integer';
202
+ }
203
+ else if (type1 === 'number' && type2 === 'integer') {
204
+ type1 = 'integer';
205
+ }
206
+ if (type1 && type2 && type1 !== type2) {
207
+ throw new convertOpenApi_1.ImpossibleSchemaError(path, "mismatched type in composition: \"".concat(type1, "\" \"").concat(type2, "\""));
208
+ }
209
+ for (var _i = 0, _c = [schema1, schema2]; _i < _c.length; _i++) {
210
+ var schema = _c[_i];
211
+ if (typeof schema.exclusiveMaximum === 'number') {
212
+ if (schema.maximum === undefined || schema.maximum >= schema.exclusiveMaximum) {
213
+ schema.maximum = schema.exclusiveMaximum;
214
+ schema.exclusiveMaximum = true;
215
+ }
216
+ else {
217
+ schema.exclusiveMaximum = undefined;
218
+ }
219
+ }
220
+ if (typeof schema.exclusiveMinimum === 'number') {
221
+ if (schema.minimum === undefined || schema.minimum <= schema.exclusiveMinimum) {
222
+ schema.minimum = schema.exclusiveMinimum;
223
+ schema.exclusiveMinimum = true;
224
+ }
225
+ else {
226
+ schema.exclusiveMinimum = undefined;
227
+ }
228
+ }
229
+ }
230
+ var combinedSchema = {
231
+ title: takeLast(schema1, schema2, 'title'),
232
+ description: takeLast(schema1, schema2, 'description'),
233
+ format: takeLast(schema1, schema2, 'format'),
234
+ multipleOf: combine(schema1, schema2, 'multipleOf', lcm_1.default),
235
+ maximum: combine(schema1, schema2, 'maximum', Math.min),
236
+ minimum: combine(schema1, schema2, 'minimum', Math.max),
237
+ maxLength: combine(schema1, schema2, 'maxLength', Math.min),
238
+ minLength: combine(schema1, schema2, 'minLength', Math.max),
239
+ maxItems: combine(schema1, schema2, 'maxItems', Math.min),
240
+ minItems: combine(schema1, schema2, 'minItems', Math.max),
241
+ maxProperties: combine(schema1, schema2, 'maxProperties', Math.min),
242
+ minProperties: combine(schema1, schema2, 'minProperties', Math.max),
243
+ required: combine(schema1, schema2, 'required', function (a, b) {
244
+ return b.concat(a.filter(function (value) { return !b.includes(value); }));
245
+ }),
246
+ enum: combine(schema1, schema2, 'enum', function (a, b) { return b.filter(function (value) { return a.includes(value); }); }),
247
+ readOnly: schema1.readOnly && schema2.readOnly,
248
+ writeOnly: schema1.writeOnly && schema2.writeOnly,
249
+ deprecated: schema1.deprecated && schema2.deprecated,
250
+ };
251
+ combinedSchema.exclusiveMaximum =
252
+ (schema1.maximum === combinedSchema.maximum ? schema1.exclusiveMaximum : undefined) ||
253
+ (schema2.maximum === combinedSchema.maximum ? schema2.exclusiveMaximum : undefined);
254
+ combinedSchema.exclusiveMinimum =
255
+ (schema1.minimum === combinedSchema.minimum ? schema1.exclusiveMinimum : undefined) ||
256
+ (schema2.minimum === combinedSchema.minimum ? schema2.exclusiveMinimum : undefined);
257
+ if (typeof schema1.example === 'object' &&
258
+ typeof schema2.example === 'object' &&
259
+ (schema1.example != null || schema2.example != null)) {
260
+ combinedSchema.example = __assign(__assign({}, schema1.example), schema2.example);
261
+ }
262
+ else {
263
+ combinedSchema.example = takeLast(schema1, schema2, 'example');
264
+ }
265
+ var type = type1 !== null && type1 !== void 0 ? type1 : type2;
266
+ if (type === 'array') {
267
+ return __assign({ type: type, items: combineReducedSchemas(__spreadArray(__spreadArray([], path, true), ['items'], false), (_a = schema1.items) !== null && _a !== void 0 ? _a : {}, (_b = schema2.items) !== null && _b !== void 0 ? _b : {}) }, combinedSchema);
268
+ }
269
+ if (schema1.properties && schema2.properties) {
270
+ var combinedProperties_1 = __assign({}, schema1.properties);
271
+ Object.entries(schema2.properties).forEach(function (_a) {
272
+ var property = _a[0], schema = _a[1];
273
+ if (property in combinedProperties_1) {
274
+ combinedProperties_1[property] = combineReducedSchemas(__spreadArray(__spreadArray([], path, true), ['properties', property], false), combinedProperties_1[property], schema);
275
+ }
276
+ else {
277
+ combinedProperties_1[property] = schema;
278
+ }
279
+ });
280
+ combinedSchema.properties = combinedProperties_1;
281
+ }
282
+ else if (schema1.properties || schema2.properties) {
283
+ combinedSchema.properties = __assign(__assign({}, schema1.properties), schema2.properties);
284
+ }
285
+ if (schema1.additionalProperties === false || schema2.additionalProperties === false) {
286
+ combinedSchema.additionalProperties = false;
287
+ }
288
+ else if (schema1.additionalProperties &&
289
+ typeof schema1.additionalProperties === 'object' &&
290
+ schema2.additionalProperties &&
291
+ typeof schema2.additionalProperties === 'object') {
292
+ combinedSchema.additionalProperties = combineReducedSchemas(__spreadArray(__spreadArray([], path, true), ['additionalProperties'], false), schema1.additionalProperties, schema2.additionalProperties);
293
+ }
294
+ else if (schema1.additionalProperties && typeof schema1.additionalProperties === 'object') {
295
+ combinedSchema.additionalProperties = schema1.additionalProperties;
296
+ }
297
+ else if (schema2.additionalProperties && typeof schema2.additionalProperties === 'object') {
298
+ combinedSchema.additionalProperties = schema2.additionalProperties;
299
+ }
300
+ return __assign({ type: type }, combinedSchema);
301
+ };
302
+ exports.combineTopLevelSchemas = combineTopLevelSchemas;
303
+ var addKeyIfDefined = function (key, value, destination) {
304
+ if (value !== undefined) {
305
+ destination[key] = value;
306
+ }
307
+ };
308
+ exports.addKeyIfDefined = addKeyIfDefined;
309
+ var copyKeyIfDefined = function (key, source, destination) {
310
+ if (source[key] !== undefined) {
311
+ destination[key] = source[key];
312
+ }
313
+ };
314
+ exports.copyKeyIfDefined = copyKeyIfDefined;
315
+ var takeLast = function (schema1, schema2, key) {
316
+ var _a;
317
+ return (_a = schema2[key]) !== null && _a !== void 0 ? _a : schema1[key];
318
+ };
319
+ var combine = function (schema1, schema2, key, transform) {
320
+ var _a;
321
+ return schema1[key] !== undefined && schema2[key] !== undefined
322
+ ? transform(schema1[key], schema2[key])
323
+ : (_a = schema1[key]) !== null && _a !== void 0 ? _a : schema2[key];
324
+ };
325
+ var convertSchemaRecursive = function (path, schema, required) {
326
+ if (schema.oneOf === undefined || schema.oneOf.length === 0) {
327
+ throw new convertOpenApi_1.ConversionError(path, 'missing schema definition');
328
+ }
329
+ var schemaArray = schema.oneOf.map(function (schema) {
330
+ var sharedProps = {};
331
+ (0, exports.addKeyIfDefined)('required', required, sharedProps);
332
+ (0, exports.copyKeyIfDefined)('title', schema, sharedProps);
333
+ (0, exports.copyKeyIfDefined)('description', schema, sharedProps);
334
+ (0, exports.copyKeyIfDefined)('readOnly', schema, sharedProps);
335
+ (0, exports.copyKeyIfDefined)('writeOnly', schema, sharedProps);
336
+ (0, exports.copyKeyIfDefined)('deprecated', schema, sharedProps);
337
+ if (schema.type === undefined) {
338
+ var inferredType = inferType(schema);
339
+ if (inferredType === undefined) {
340
+ return __assign({ type: 'any' }, sharedProps);
341
+ }
342
+ schema.type = inferredType;
343
+ }
344
+ var type = schema.type;
345
+ if (!endpoint_1.typeList.includes(type)) {
346
+ throw new convertOpenApi_1.InvalidSchemaError(path, "invalid schema type: ".concat(schema.type));
347
+ }
348
+ switch (schema.type) {
349
+ case 'boolean':
350
+ var booleanProps = sharedProps;
351
+ (0, exports.copyKeyIfDefined)('default', schema, booleanProps);
352
+ (0, exports.copyKeyIfDefined)('example', schema, booleanProps);
353
+ return __assign({ type: schema.type }, booleanProps);
354
+ case 'number':
355
+ case 'integer':
356
+ if (schema.enum) {
357
+ var numberEnumProps = sharedProps;
358
+ (0, exports.copyKeyIfDefined)('default', schema, numberEnumProps);
359
+ (0, exports.copyKeyIfDefined)('example', schema, numberEnumProps);
360
+ return __assign({ type: schema.type === 'number' ? 'numberEnum' : 'integerEnum', enum: schema.enum }, numberEnumProps);
361
+ }
362
+ var numberProps = sharedProps;
363
+ (0, exports.copyKeyIfDefined)('multipleOf', schema, numberProps);
364
+ (0, exports.copyKeyIfDefined)('maximum', schema, numberProps);
365
+ (0, exports.copyKeyIfDefined)('exclusiveMaximum', schema, numberProps);
366
+ (0, exports.copyKeyIfDefined)('minimum', schema, numberProps);
367
+ (0, exports.copyKeyIfDefined)('exclusiveMinimum', schema, numberProps);
368
+ (0, exports.copyKeyIfDefined)('default', schema, numberProps);
369
+ (0, exports.copyKeyIfDefined)('example', schema, numberProps);
370
+ return __assign({ type: schema.type }, numberProps);
371
+ case 'string':
372
+ if (schema.enum) {
373
+ var stringEnumProps = sharedProps;
374
+ (0, exports.copyKeyIfDefined)('default', schema, stringEnumProps);
375
+ (0, exports.copyKeyIfDefined)('example', schema, stringEnumProps);
376
+ return __assign({ type: 'stringEnum', enum: schema.enum }, stringEnumProps);
377
+ }
378
+ var stringProps = sharedProps;
379
+ (0, exports.copyKeyIfDefined)('format', schema, stringProps);
380
+ (0, exports.copyKeyIfDefined)('pattern', schema, stringProps);
381
+ (0, exports.copyKeyIfDefined)('maxLength', schema, stringProps);
382
+ (0, exports.copyKeyIfDefined)('minLength', schema, stringProps);
383
+ (0, exports.copyKeyIfDefined)('default', schema, stringProps);
384
+ (0, exports.copyKeyIfDefined)('example', schema, stringProps);
385
+ return __assign({ type: schema.type }, stringProps);
386
+ case 'array':
387
+ var arrayProps = sharedProps;
388
+ (0, exports.copyKeyIfDefined)('maxItems', schema, arrayProps);
389
+ (0, exports.copyKeyIfDefined)('minItems', schema, arrayProps);
390
+ (0, exports.copyKeyIfDefined)('uniqueItems', schema, arrayProps);
391
+ (0, exports.copyKeyIfDefined)('default', schema, arrayProps);
392
+ (0, exports.copyKeyIfDefined)('example', schema, arrayProps);
393
+ return __assign({ type: schema.type, items: convertSchemaRecursive(__spreadArray(__spreadArray([], path, true), ['items'], false), schema.items) }, arrayProps);
394
+ case 'object':
395
+ var properties = (0, exports.convertProperties)(__spreadArray(__spreadArray([], path, true), ['properties'], false), schema.properties, schema.required);
396
+ var additionalProperties = typeof schema.additionalProperties === 'object' && schema.additionalProperties != null
397
+ ? convertSchemaRecursive(__spreadArray(__spreadArray([], path, true), ['additionalProperties'], false), schema.additionalProperties)
398
+ : schema.additionalProperties;
399
+ var objectProperties = sharedProps;
400
+ (0, exports.addKeyIfDefined)('additionalProperties', additionalProperties, objectProperties);
401
+ (0, exports.copyKeyIfDefined)('maxProperties', schema, objectProperties);
402
+ (0, exports.copyKeyIfDefined)('minProperties', schema, objectProperties);
403
+ (0, exports.copyKeyIfDefined)('default', schema, objectProperties);
404
+ (0, exports.copyKeyIfDefined)('example', schema, objectProperties);
405
+ return __assign({ type: schema.type, properties: properties }, objectProperties);
406
+ case 'null':
407
+ var nullProps = sharedProps;
408
+ (0, exports.copyKeyIfDefined)('default', schema, nullProps);
409
+ (0, exports.copyKeyIfDefined)('example', schema, nullProps);
410
+ return __assign({ type: schema.type }, nullProps);
411
+ default:
412
+ throw new convertOpenApi_1.ImpossibleSchemaError(path, "impossible type reached: ".concat(schema.type));
413
+ }
414
+ });
415
+ // must unpack first element to satisfy type
416
+ return __spreadArray([schemaArray[0]], schemaArray.slice(1), true);
417
+ };
418
+ var convertProperties = function (path, properties, required) {
419
+ if (properties === undefined) {
420
+ return {};
421
+ }
422
+ var newEntries = Object.entries(properties).map(function (_a) {
423
+ var name = _a[0], schema = _a[1];
424
+ return [
425
+ name,
426
+ convertSchemaRecursive(__spreadArray(__spreadArray([], path, true), [name], false), schema, (required === null || required === void 0 ? void 0 : required.includes(name)) ? true : undefined),
427
+ ];
428
+ });
429
+ return Object.fromEntries(newEntries);
430
+ };
431
+ exports.convertProperties = convertProperties;
432
+ /**
433
+ * Given an OpenAPI 3.1 schema, this function will attempt to determine the schema type
434
+ * based on the properties present in the schema. This is useful for assigning types to
435
+ * schemas that are missing a type.
436
+ *
437
+ * For example, if a schema has no type but has `schema.properties`, we can infer the
438
+ * intended type is `object`.
439
+ *
440
+ * @param schema
441
+ * @returns if exactly one type can be inferred, the string corresponding to that type; otherwise `undefined`
442
+ */
443
+ var inferType = function (schema) {
444
+ var _a, _b;
445
+ var type = undefined;
446
+ if (schema.format !== undefined ||
447
+ schema.pattern !== undefined ||
448
+ schema.minLength !== undefined ||
449
+ schema.maxLength !== undefined ||
450
+ ((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.every(function (option) { return typeof option === 'string'; }))) {
451
+ if (type !== undefined) {
452
+ return undefined;
453
+ }
454
+ type = 'string';
455
+ }
456
+ if (schema.multipleOf !== undefined ||
457
+ schema.minimum !== undefined ||
458
+ schema.maximum !== undefined ||
459
+ schema.exclusiveMinimum !== undefined ||
460
+ schema.exclusiveMaximum !== undefined ||
461
+ ((_b = schema.enum) === null || _b === void 0 ? void 0 : _b.every(function (option) { return typeof option === 'number'; }))) {
462
+ if (type !== undefined) {
463
+ return undefined;
464
+ }
465
+ type = 'number'; // less specific than 'integer'
466
+ }
467
+ if (schema.items !== undefined ||
468
+ schema.minItems !== undefined ||
469
+ schema.maxItems !== undefined ||
470
+ schema.uniqueItems !== undefined) {
471
+ if (type !== undefined) {
472
+ return undefined;
473
+ }
474
+ type = 'array';
475
+ }
476
+ if (schema.additionalProperties !== undefined ||
477
+ schema.properties !== undefined ||
478
+ schema.minProperties !== undefined ||
479
+ schema.maxProperties !== undefined) {
480
+ if (type !== undefined) {
481
+ return undefined;
482
+ }
483
+ type = 'object';
484
+ }
485
+ return type;
486
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSecurityParameters = exports.convertSecurity = void 0;
4
+ var convertOpenApi_1 = require("./convertOpenApi");
5
+ var convertSecurity = function (_a) {
6
+ var securityRequirements = _a.securityRequirements, securitySchemes = _a.securitySchemes;
7
+ if (securityRequirements === undefined || securityRequirements.length === 0) {
8
+ return [];
9
+ }
10
+ if (securitySchemes === undefined) {
11
+ throw new convertOpenApi_1.InvalidSchemaError(['#', 'components'], 'securitySchemes not defined');
12
+ }
13
+ // TODO(ronan): make this work for camel-case as well
14
+ return securityRequirements.map(function (security) {
15
+ var title = Object.keys(security)
16
+ .map(function (securityName) { return securityName.replace(/[_-]/g, ' '); })
17
+ .join(' & ');
18
+ var parameterSections = {
19
+ title: title,
20
+ query: {},
21
+ header: {},
22
+ cookie: {},
23
+ };
24
+ Object.keys(security).forEach(function (securityName) {
25
+ var securityScheme = securitySchemes === null || securitySchemes === void 0 ? void 0 : securitySchemes[securityName];
26
+ if (securityScheme === undefined) {
27
+ throw new convertOpenApi_1.InvalidSchemaError(['#', 'components', 'securitySchemes'], "security scheme not defined: '".concat(securityName, "'"));
28
+ }
29
+ (0, exports.addSecurityParameters)({
30
+ securityName: securityName,
31
+ securityScheme: securityScheme,
32
+ parameterSections: parameterSections,
33
+ });
34
+ });
35
+ return parameterSections;
36
+ });
37
+ };
38
+ exports.convertSecurity = convertSecurity;
39
+ var addSecurityParameters = function (_a) {
40
+ var _b, _c;
41
+ var securityName = _a.securityName, securityScheme = _a.securityScheme, parameterSections = _a.parameterSections;
42
+ switch (securityScheme.type) {
43
+ case 'apiKey':
44
+ if (!['header', 'query', 'cookie'].includes(securityScheme.in)) {
45
+ throw new convertOpenApi_1.InvalidSchemaError(['#', 'components', 'securitySchemes', securityName], "invalid security scheme location provided: '".concat(securityScheme.in, "'"));
46
+ }
47
+ var paramGroup = securityScheme.in;
48
+ parameterSections[paramGroup][securityScheme.name] = {
49
+ description: securityScheme.description,
50
+ required: true,
51
+ deprecated: false,
52
+ schema: [
53
+ {
54
+ type: 'string',
55
+ required: true,
56
+ deprecated: false,
57
+ },
58
+ ],
59
+ };
60
+ return;
61
+ case 'http':
62
+ if (securityScheme.scheme === 'basic') {
63
+ parameterSections.header['Authentication'] = {
64
+ description: (_b = securityScheme.description) !== null && _b !== void 0 ? _b : 'Basic authentication header of the form `Basic <encoded-value>`, where `<encoded-value>` is the base64-encoded string `username:password`.',
65
+ required: true,
66
+ schema: 'basic',
67
+ deprecated: false,
68
+ };
69
+ }
70
+ else if (securityScheme.scheme === 'bearer') {
71
+ parameterSections.header['Authorization'] = {
72
+ description: (_c = securityScheme.description) !== null && _c !== void 0 ? _c : 'Bearer authentication header of the form `Bearer <token>`, where `<token>` is your auth token.',
73
+ required: true,
74
+ schema: 'bearer',
75
+ deprecated: false,
76
+ };
77
+ }
78
+ else {
79
+ throw new convertOpenApi_1.InvalidSchemaError(['#', 'components', 'securitySchemes', securityName], "encountered unknown HTTP security scheme: '".concat(securityScheme.scheme, "'"));
80
+ }
81
+ return;
82
+ case 'oauth2':
83
+ case 'openIdConnect':
84
+ return;
85
+ }
86
+ };
87
+ exports.addSecurityParameters = addSecurityParameters;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertServers = void 0;
4
+ var convertServers = function (_a) {
5
+ var servers = _a.servers;
6
+ if (servers === undefined || servers.length === 0) {
7
+ return undefined;
8
+ }
9
+ return servers.map(function (_a) {
10
+ var url = _a.url, description = _a.description, variables = _a.variables;
11
+ return {
12
+ url: url,
13
+ description: description,
14
+ variables: convertVariables({ variables: variables }),
15
+ };
16
+ });
17
+ };
18
+ exports.convertServers = convertServers;
19
+ var convertVariables = function (_a) {
20
+ var variables = _a.variables;
21
+ if (variables === undefined || Object.keys(variables).length === 0) {
22
+ return undefined;
23
+ }
24
+ var newEntries = Object.entries(variables).map(function (_a) {
25
+ var name = _a[0], variable = _a[1];
26
+ if (variable.enum) {
27
+ return [
28
+ name,
29
+ {
30
+ type: 'stringEnum',
31
+ enum: variable.enum,
32
+ description: variable.description,
33
+ default: variable.default,
34
+ },
35
+ ];
36
+ }
37
+ return [
38
+ name,
39
+ {
40
+ type: 'string',
41
+ description: variable.description,
42
+ default: variable.default,
43
+ },
44
+ ];
45
+ });
46
+ return Object.fromEntries(newEntries);
47
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeList = void 0;
4
+ exports.typeList = [
5
+ 'boolean',
6
+ 'string',
7
+ 'number',
8
+ 'integer',
9
+ 'object',
10
+ 'array',
11
+ 'stringEnum',
12
+ 'numberEnum',
13
+ 'integerEnum',
14
+ 'null',
15
+ 'any',
16
+ ];