@mintlify/validation 0.1.58 → 0.1.60

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