@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.
- package/dist/index.js +17 -23
- package/dist/mint-config/common.js +3 -5
- package/dist/mint-config/flattenUnionErrorMessages.js +3 -12
- package/dist/mint-config/hexadecimalPattern.js +1 -1
- package/dist/mint-config/schemas/analytics.js +15 -15
- package/dist/mint-config/schemas/anchorColors.js +2 -2
- package/dist/mint-config/schemas/anchors.js +5 -5
- package/dist/mint-config/schemas/apiReference.js +4 -4
- package/dist/mint-config/schemas/basics.js +46 -48
- package/dist/mint-config/schemas/colors.js +1 -1
- package/dist/mint-config/schemas/config.js +1 -1
- package/dist/mint-config/schemas/favicon.js +2 -2
- package/dist/mint-config/schemas/integrations.js +3 -3
- package/dist/mint-config/schemas/navigation.js +7 -9
- package/dist/mint-config/schemas/tabs.js +3 -3
- package/dist/mint-config/schemas/versions.js +2 -2
- package/dist/mint-config/validateAnchorsWarnings.js +4 -4
- package/dist/mint-config/validateVersionsInNavigation.js +12 -15
- package/dist/openapi/convertOpenApi.js +65 -121
- package/dist/openapi/convertParameters.js +15 -26
- package/dist/openapi/convertSchema.js +89 -118
- package/dist/openapi/convertSecurity.js +19 -21
- package/dist/openapi/convertServers.js +7 -11
- package/dist/openapi/types/endpoint.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -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
|
|
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
|
-
|
|
41
|
-
|
|
20
|
+
const evaluateOptionsCompositions = (path, schemaArray) => {
|
|
21
|
+
const evaluatedArray = schemaArray.flatMap((subschema, i) => {
|
|
42
22
|
var _a;
|
|
43
23
|
try {
|
|
44
|
-
return (_a = evaluateCompositionsRecursive(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
49
|
+
schema.anyOf = evaluateOptionsCompositions([...path, 'anyOf'], schema.anyOf);
|
|
70
50
|
}
|
|
71
51
|
if (schema.allOf && schema.allOf.length > 0) {
|
|
72
|
-
|
|
73
|
-
.map(
|
|
74
|
-
|
|
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 (
|
|
86
|
-
schema.properties[key] = evaluateCompositionsRecursive(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
85
|
+
const topLevelSchemaArray = generateTopLevelSchemaArray(schema);
|
|
110
86
|
return { oneOf: multiplySchemaArrays(path, schema.oneOf, topLevelSchemaArray) };
|
|
111
87
|
};
|
|
112
|
-
|
|
88
|
+
const generateTopLevelSchemaArray = (schema) => {
|
|
113
89
|
if (schema.nullable) {
|
|
114
|
-
|
|
90
|
+
const typedSchema = Object.assign({}, schema);
|
|
115
91
|
delete typedSchema.oneOf;
|
|
116
92
|
delete typedSchema.nullable;
|
|
117
|
-
|
|
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
|
-
|
|
126
|
-
delete
|
|
127
|
-
delete
|
|
128
|
-
return [
|
|
101
|
+
const topLevelSchema = Object.assign({}, schema);
|
|
102
|
+
delete topLevelSchema.oneOf;
|
|
103
|
+
delete topLevelSchema.type;
|
|
104
|
+
return [topLevelSchema];
|
|
129
105
|
}
|
|
130
|
-
return schema.type.map(
|
|
131
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
-
return b.flatMap(
|
|
137
|
+
const product = a.flatMap((schema1) => {
|
|
138
|
+
return b.flatMap((schema2) => {
|
|
163
139
|
try {
|
|
164
|
-
|
|
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
|
-
|
|
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
|
|
164
|
+
export const combineTopLevelSchemas = (path, schema1, schema2) => {
|
|
189
165
|
var _a, _b;
|
|
190
|
-
|
|
191
|
-
|
|
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,
|
|
176
|
+
throw new ImpossibleSchemaError(path, `mismatched type in composition: "${type1}" "${type2}"`);
|
|
201
177
|
}
|
|
202
|
-
for (
|
|
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
|
-
|
|
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',
|
|
237
|
-
|
|
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 =
|
|
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
|
-
|
|
231
|
+
const type = type1 !== null && type1 !== void 0 ? type1 : type2;
|
|
259
232
|
if (type === 'array') {
|
|
260
|
-
return
|
|
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
|
-
|
|
264
|
-
Object.entries(schema2.properties).forEach(
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
242
|
+
combinedProperties[property] = schema;
|
|
271
243
|
}
|
|
272
244
|
});
|
|
273
|
-
combinedSchema.properties =
|
|
245
|
+
combinedSchema.properties = combinedProperties;
|
|
274
246
|
}
|
|
275
247
|
else if (schema1.properties || schema2.properties) {
|
|
276
|
-
combinedSchema.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(
|
|
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
|
|
265
|
+
return Object.assign({ type }, combinedSchema);
|
|
294
266
|
};
|
|
295
|
-
export
|
|
267
|
+
export const addKeyIfDefined = (key, value, destination) => {
|
|
296
268
|
if (value !== undefined) {
|
|
297
269
|
destination[key] = value;
|
|
298
270
|
}
|
|
299
271
|
};
|
|
300
|
-
export
|
|
272
|
+
export const copyKeyIfDefined = (key, source, destination) => {
|
|
301
273
|
if (source[key] !== undefined) {
|
|
302
274
|
destination[key] = source[key];
|
|
303
275
|
}
|
|
304
276
|
};
|
|
305
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
320
|
-
|
|
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
|
-
|
|
300
|
+
const inferredType = inferType(schema);
|
|
329
301
|
if (inferredType === undefined) {
|
|
330
|
-
return
|
|
302
|
+
return Object.assign({ type: 'any' }, sharedProps);
|
|
331
303
|
}
|
|
332
304
|
schema.type = inferredType;
|
|
333
305
|
}
|
|
334
|
-
|
|
306
|
+
const type = schema.type;
|
|
335
307
|
if (!typeList.includes(type)) {
|
|
336
|
-
throw new InvalidSchemaError(path,
|
|
308
|
+
throw new InvalidSchemaError(path, `invalid schema type: ${schema.type}`);
|
|
337
309
|
}
|
|
338
310
|
switch (schema.type) {
|
|
339
311
|
case 'boolean':
|
|
340
|
-
|
|
312
|
+
const booleanProps = sharedProps;
|
|
341
313
|
copyKeyIfDefined('default', schema, booleanProps);
|
|
342
314
|
copyKeyIfDefined('example', schema, booleanProps);
|
|
343
|
-
return
|
|
315
|
+
return Object.assign({ type: schema.type }, booleanProps);
|
|
344
316
|
case 'number':
|
|
345
317
|
case 'integer':
|
|
346
318
|
if (schema.enum) {
|
|
347
|
-
|
|
319
|
+
const numberEnumProps = sharedProps;
|
|
348
320
|
copyKeyIfDefined('default', schema, numberEnumProps);
|
|
349
321
|
copyKeyIfDefined('example', schema, numberEnumProps);
|
|
350
|
-
return
|
|
322
|
+
return Object.assign({ type: schema.type === 'number' ? 'numberEnum' : 'integerEnum', enum: schema.enum }, numberEnumProps);
|
|
351
323
|
}
|
|
352
|
-
|
|
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
|
|
332
|
+
return Object.assign({ type: schema.type }, numberProps);
|
|
361
333
|
case 'string':
|
|
362
334
|
if (schema.enum) {
|
|
363
|
-
|
|
335
|
+
const stringEnumProps = sharedProps;
|
|
364
336
|
copyKeyIfDefined('default', schema, stringEnumProps);
|
|
365
337
|
copyKeyIfDefined('example', schema, stringEnumProps);
|
|
366
|
-
return
|
|
338
|
+
return Object.assign({ type: 'stringEnum', enum: schema.enum }, stringEnumProps);
|
|
367
339
|
}
|
|
368
|
-
|
|
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
|
|
347
|
+
return Object.assign({ type: schema.type }, stringProps);
|
|
376
348
|
case 'array':
|
|
377
|
-
|
|
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
|
|
355
|
+
return Object.assign({ type: schema.type, items: convertSchemaRecursive([...path, 'items'], schema.items) }, arrayProps);
|
|
384
356
|
case 'object':
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
? convertSchemaRecursive(
|
|
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
|
-
|
|
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
|
|
367
|
+
return Object.assign({ type: schema.type, properties }, objectProperties);
|
|
396
368
|
case 'null':
|
|
397
|
-
|
|
369
|
+
const nullProps = sharedProps;
|
|
398
370
|
copyKeyIfDefined('default', schema, nullProps);
|
|
399
371
|
copyKeyIfDefined('example', schema, nullProps);
|
|
400
|
-
return
|
|
372
|
+
return Object.assign({ type: schema.type }, nullProps);
|
|
401
373
|
default:
|
|
402
|
-
throw new ImpossibleSchemaError(path,
|
|
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
|
|
378
|
+
return [schemaArray[0], ...schemaArray.slice(1)];
|
|
407
379
|
};
|
|
408
|
-
export
|
|
380
|
+
export const convertProperties = (path, properties, required) => {
|
|
409
381
|
if (properties === undefined) {
|
|
410
382
|
return {};
|
|
411
383
|
}
|
|
412
|
-
|
|
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(
|
|
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
|
-
|
|
403
|
+
const inferType = (schema) => {
|
|
433
404
|
var _a, _b;
|
|
434
|
-
|
|
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(
|
|
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(
|
|
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
|
|
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(
|
|
12
|
-
|
|
13
|
-
.map(
|
|
10
|
+
return securityRequirements.map((security) => {
|
|
11
|
+
const title = Object.keys(security)
|
|
12
|
+
.map((securityName) => securityName.replace(/[_-]/g, ' '))
|
|
14
13
|
.join(' & ');
|
|
15
|
-
|
|
16
|
-
title
|
|
14
|
+
const parameterSections = {
|
|
15
|
+
title,
|
|
17
16
|
query: {},
|
|
18
17
|
header: {},
|
|
19
18
|
cookie: {},
|
|
20
19
|
};
|
|
21
|
-
Object.keys(security).forEach(
|
|
22
|
-
|
|
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'],
|
|
23
|
+
throw new InvalidSchemaError(['#', 'components', 'securitySchemes'], `security scheme not defined: '${securityName}'`);
|
|
25
24
|
}
|
|
26
25
|
addSecurityParameters({
|
|
27
|
-
securityName
|
|
28
|
-
securityScheme
|
|
29
|
-
parameterSections
|
|
26
|
+
securityName,
|
|
27
|
+
securityScheme,
|
|
28
|
+
parameterSections,
|
|
30
29
|
});
|
|
31
30
|
});
|
|
32
31
|
return parameterSections;
|
|
33
32
|
});
|
|
34
33
|
};
|
|
35
|
-
export
|
|
36
|
-
var
|
|
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],
|
|
39
|
+
throw new InvalidSchemaError(['#', 'components', 'securitySchemes', securityName], `invalid security scheme location provided: '${securityScheme.in}'`);
|
|
42
40
|
}
|
|
43
|
-
|
|
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: (
|
|
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: (
|
|
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],
|
|
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
|
|
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(
|
|
7
|
-
var url = _a.url, description = _a.description, variables = _a.variables;
|
|
5
|
+
return servers.map(({ url, description, variables }) => {
|
|
8
6
|
return {
|
|
9
|
-
url
|
|
10
|
-
description
|
|
11
|
-
variables: convertVariables({ variables
|
|
7
|
+
url,
|
|
8
|
+
description,
|
|
9
|
+
variables: convertVariables({ variables }),
|
|
12
10
|
};
|
|
13
11
|
});
|
|
14
12
|
};
|
|
15
|
-
|
|
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
|
-
|
|
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,
|