@mintlify/validation 0.1.67 → 0.1.68

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