openapi-explorer 2.1.656 → 2.1.658
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/browser/openapi-explorer.min.js +2 -2
- package/dist/es/components/api-request.js +58 -140
- package/dist/es/components/api-response.js +9 -34
- package/dist/es/components/json-tree.js +4 -18
- package/dist/es/components/request-form-table.js +13 -36
- package/dist/es/components/schema-table.js +28 -42
- package/dist/es/components/schema-tree.js +31 -61
- package/dist/es/components/syntax-highlighter.js +7 -26
- package/dist/es/components/tag-input.js +2 -14
- package/dist/es/openapi-explorer-oauth-handler.js +0 -2
- package/dist/es/openapi-explorer.js +62 -174
- package/dist/es/react.js +4 -4
- package/dist/es/styles/input-styles.js +1 -1
- package/dist/es/styles/schema-styles.js +1 -1
- package/dist/es/templates/advance-search-template.js +1 -5
- package/dist/es/templates/callback-template.js +2 -2
- package/dist/es/templates/code-samples-template.js +1 -3
- package/dist/es/templates/components-template.js +41 -4
- package/dist/es/templates/endpoint-template.js +6 -17
- package/dist/es/templates/expanded-endpoint-template.js +4 -7
- package/dist/es/templates/focused-endpoint-template.js +0 -10
- package/dist/es/templates/mainBodyTemplate.js +3 -2
- package/dist/es/templates/navbar-template.js +9 -12
- package/dist/es/templates/overview-template.js +1 -1
- package/dist/es/templates/security-scheme-template.js +12 -73
- package/dist/es/templates/server-template.js +1 -8
- package/dist/es/utils/color-utils.js +2 -21
- package/dist/es/utils/common-utils.js +3 -20
- package/dist/es/utils/schema-utils.js +35 -132
- package/dist/es/utils/spec-parser.js +35 -120
- package/dist/es/utils/theme.js +3 -6
- package/dist/es/utils/xml/xml.js +1 -40
- package/dist/lib/components/api-request.js +58 -157
- package/dist/lib/components/api-response.js +9 -54
- package/dist/lib/components/json-tree.js +4 -27
- package/dist/lib/components/request-form-table.js +14 -42
- package/dist/lib/components/schema-table.js +28 -52
- package/dist/lib/components/schema-tree.js +31 -72
- package/dist/lib/components/syntax-highlighter.js +6 -49
- package/dist/lib/components/tag-input.js +2 -18
- package/dist/lib/languages/en.js +2 -3
- package/dist/lib/languages/fr.js +2 -3
- package/dist/lib/languages/index.js +0 -6
- package/dist/lib/openapi-explorer-oauth-handler.js +0 -6
- package/dist/lib/openapi-explorer.js +61 -197
- package/dist/lib/react.js +4 -5
- package/dist/lib/styles/advanced-search-styles.js +1 -5
- package/dist/lib/styles/api-request-styles.js +1 -5
- package/dist/lib/styles/border-styles.js +1 -5
- package/dist/lib/styles/endpoint-styles.js +1 -5
- package/dist/lib/styles/flex-styles.js +1 -5
- package/dist/lib/styles/font-styles.js +1 -5
- package/dist/lib/styles/info-styles.js +1 -5
- package/dist/lib/styles/input-styles.js +1 -5
- package/dist/lib/styles/key-frame-styles.js +1 -5
- package/dist/lib/styles/nav-styles.js +1 -5
- package/dist/lib/styles/prism-styles.js +1 -5
- package/dist/lib/styles/schema-styles.js +1 -5
- package/dist/lib/styles/tab-styles.js +1 -5
- package/dist/lib/styles/table-styles.js +1 -5
- package/dist/lib/styles/tag-input-styles.js +1 -5
- package/dist/lib/templates/advance-search-template.js +0 -6
- package/dist/lib/templates/callback-template.js +1 -3
- package/dist/lib/templates/code-samples-template.js +0 -4
- package/dist/lib/templates/components-template.js +43 -9
- package/dist/lib/templates/endpoint-template.js +6 -29
- package/dist/lib/templates/expanded-endpoint-template.js +3 -17
- package/dist/lib/templates/focused-endpoint-template.js +0 -19
- package/dist/lib/templates/mainBodyTemplate.js +2 -13
- package/dist/lib/templates/navbar-template.js +9 -20
- package/dist/lib/templates/overview-template.js +0 -5
- package/dist/lib/templates/security-scheme-template.js +12 -79
- package/dist/lib/templates/server-template.js +1 -12
- package/dist/lib/utils/color-utils.js +4 -25
- package/dist/lib/utils/common-utils.js +3 -33
- package/dist/lib/utils/schema-utils.js +33 -141
- package/dist/lib/utils/spec-parser.js +35 -128
- package/dist/lib/utils/theme.js +3 -16
- package/dist/lib/utils/xml/xml.js +1 -42
- package/package.json +2 -2
@@ -7,34 +7,25 @@ exports.getSampleValueByType = getSampleValueByType;
|
|
7
7
|
exports.getTypeInfo = getTypeInfo;
|
8
8
|
exports.isPatternProperty = isPatternProperty;
|
9
9
|
exports.schemaInObjectNotation = schemaInObjectNotation;
|
10
|
-
|
11
10
|
var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
|
12
|
-
|
13
11
|
var _lodash2 = _interopRequireDefault(require("lodash.merge"));
|
14
|
-
|
15
12
|
var _randexp = _interopRequireDefault(require("randexp"));
|
16
|
-
|
17
13
|
var _xml = _interopRequireDefault(require("./xml/xml.js"));
|
18
|
-
|
19
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
|
-
|
21
15
|
// When the type is not known for a property set the displayed type to be this:
|
22
16
|
const IS_MISSING_TYPE_INFO_TYPE = '';
|
23
17
|
const EXAMPLE_VALUE_FOR_MISSING_TYPE = '';
|
24
|
-
/* Generates an schema object containing type and constraint info */
|
25
18
|
|
19
|
+
/* Generates an schema object containing type and constraint info */
|
26
20
|
function getTypeInfo(schema, options = {
|
27
21
|
includeNulls: false
|
28
22
|
}) {
|
29
23
|
var _schema$items, _schema$const;
|
30
|
-
|
31
24
|
if (!schema) {
|
32
25
|
return undefined;
|
33
26
|
}
|
34
|
-
|
35
27
|
let dataType = IS_MISSING_TYPE_INFO_TYPE;
|
36
28
|
let format = schema.format || ((_schema$items = schema.items) === null || _schema$items === void 0 ? void 0 : _schema$items.format) || '';
|
37
|
-
|
38
29
|
if (schema.circularReference) {
|
39
30
|
dataType = `{recursive: ${schema.circularReference.name}} `;
|
40
31
|
} else if (schema.type) {
|
@@ -43,16 +34,13 @@ function getTypeInfo(schema, options = {
|
|
43
34
|
['string', 'number'].forEach(type => {
|
44
35
|
dataType = dataType.replace(type, typeof schema.const !== 'undefined' && 'const' || schema.enum && `${type} enum` || schema.format || type);
|
45
36
|
});
|
46
|
-
|
47
37
|
if (schema.nullable && options.includeNulls) {
|
48
38
|
dataType += '┃null';
|
49
39
|
}
|
50
|
-
|
51
40
|
if (dataType.includes('┃null') && schema.format) {
|
52
41
|
format += '┃null';
|
53
42
|
}
|
54
43
|
}
|
55
|
-
|
56
44
|
const info = {
|
57
45
|
type: dataType,
|
58
46
|
format,
|
@@ -68,38 +56,30 @@ function getTypeInfo(schema, options = {
|
|
68
56
|
allowedValues: (_schema$const = schema.const) !== null && _schema$const !== void 0 ? _schema$const : Array.isArray(schema.enum) ? schema.enum.join('┃') : '',
|
69
57
|
arrayType: ''
|
70
58
|
};
|
71
|
-
|
72
59
|
if (dataType === 'array' && schema.items) {
|
73
60
|
var _ref, _schema$items$default, _schema$const2;
|
74
|
-
|
75
61
|
const arrayItemType = schema.items.type;
|
76
62
|
const arrayItemDefault = (_ref = (_schema$items$default = schema.items.default) !== null && _schema$items$default !== void 0 ? _schema$items$default : schema.default) !== null && _ref !== void 0 ? _ref : '';
|
77
63
|
info.arrayType = `${schema.type} of ${Array.isArray(arrayItemType) ? arrayItemType.join('') : arrayItemType}`;
|
78
64
|
info.default = arrayItemDefault;
|
79
65
|
info.allowedValues = (_schema$const2 = schema.const) !== null && _schema$const2 !== void 0 ? _schema$const2 : Array.isArray(schema.items.enum) ? schema.items.enum.join('┃') : '';
|
80
66
|
}
|
81
|
-
|
82
67
|
if (schema.uniqueItems) {
|
83
68
|
info.constraints.push('Requires unique items');
|
84
69
|
}
|
85
|
-
|
86
70
|
if (dataType.match(/integer|number/g)) {
|
87
71
|
var _schema$minimum, _schema$maximum;
|
88
|
-
|
89
72
|
const minimum = (_schema$minimum = schema.minimum) !== null && _schema$minimum !== void 0 ? _schema$minimum : schema.exclusiveMinimum;
|
90
73
|
const maximum = (_schema$maximum = schema.maximum) !== null && _schema$maximum !== void 0 ? _schema$maximum : schema.exclusiveMaximum;
|
91
74
|
const leftBound = schema.minimum !== undefined ? '[' : '(';
|
92
75
|
const rightBound = schema.maximum !== undefined ? ']' : ')';
|
93
|
-
|
94
76
|
if (typeof minimum === 'number' || typeof maximum === 'number') {
|
95
77
|
info.constraints.push(`Range: ${leftBound}${minimum !== null && minimum !== void 0 ? minimum : ''},${maximum !== null && maximum !== void 0 ? maximum : ''}${rightBound}`);
|
96
78
|
}
|
97
|
-
|
98
79
|
if (schema.multipleOf !== undefined) {
|
99
80
|
info.constraints.push(`Multiples: ${schema.multipleOf}`);
|
100
81
|
}
|
101
82
|
}
|
102
|
-
|
103
83
|
if (dataType.match(/string/g)) {
|
104
84
|
if (schema.minLength !== undefined && schema.maxLength !== undefined) {
|
105
85
|
info.constraints.push(`Min length: ${schema.minLength}, Max length: ${schema.maxLength}`);
|
@@ -109,7 +89,6 @@ function getTypeInfo(schema, options = {
|
|
109
89
|
info.constraints.push(`Max length: ${schema.maxLength}`);
|
110
90
|
}
|
111
91
|
}
|
112
|
-
|
113
92
|
info.html = JSON.stringify({
|
114
93
|
type: info.type,
|
115
94
|
format: info.format,
|
@@ -126,42 +105,31 @@ function getTypeInfo(schema, options = {
|
|
126
105
|
});
|
127
106
|
return info;
|
128
107
|
}
|
129
|
-
|
130
108
|
function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleIds) {
|
131
109
|
var _Object$values$0$valu, _Object$values$, _schemaObj$type;
|
132
|
-
|
133
110
|
const example = Array.isArray(schemaObj.examples) ? schemaObj.examples[0] : (_Object$values$0$valu = (_Object$values$ = Object.values(schemaObj.examples || {})[0]) === null || _Object$values$ === void 0 ? void 0 : _Object$values$.value) !== null && _Object$values$0$valu !== void 0 ? _Object$values$0$valu : schemaObj.example;
|
134
|
-
|
135
111
|
if (skipExampleIds && typeof example === 'string' && fallbackPropertyName.match(/id$/i)) {
|
136
112
|
return '';
|
137
113
|
}
|
138
|
-
|
139
114
|
if (typeof example !== 'undefined') {
|
140
115
|
return example;
|
141
116
|
}
|
142
|
-
|
143
117
|
if (schemaObj.default) {
|
144
118
|
return schemaObj.default;
|
145
119
|
}
|
146
|
-
|
147
120
|
if (Object.keys(schemaObj).length === 0) {
|
148
121
|
return EXAMPLE_VALUE_FOR_MISSING_TYPE;
|
149
122
|
}
|
150
|
-
|
151
123
|
if (schemaObj.circularReference) {
|
152
124
|
return schemaObj.$ref;
|
153
125
|
}
|
154
|
-
|
155
126
|
const typeValue = Array.isArray(schemaObj.type) ? schemaObj.type.filter(t => t !== 'null')[0] : (_schemaObj$type = schemaObj.type) !== null && _schemaObj$type !== void 0 ? _schemaObj$type : '';
|
156
|
-
|
157
127
|
if (typeof schemaObj.const !== 'undefined') {
|
158
128
|
return schemaObj.const;
|
159
129
|
}
|
160
|
-
|
161
130
|
if (schemaObj.enum) {
|
162
131
|
return schemaObj.enum[0];
|
163
132
|
}
|
164
|
-
|
165
133
|
if (typeValue.match(/^integer|^number/g)) {
|
166
134
|
const multipleOf = Number.isNaN(Number(schemaObj.multipleOf)) ? undefined : Number(schemaObj.multipleOf);
|
167
135
|
const maximum = Number.isNaN(Number(schemaObj.maximum)) ? undefined : Number(schemaObj.maximum);
|
@@ -169,94 +137,74 @@ function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleIds) {
|
|
169
137
|
const finalVal = multipleOf ? multipleOf >= minimumPossibleVal ? multipleOf : minimumPossibleVal % multipleOf === 0 ? minimumPossibleVal : Math.ceil(minimumPossibleVal / multipleOf) * multipleOf : minimumPossibleVal;
|
170
138
|
return finalVal;
|
171
139
|
}
|
172
|
-
|
173
140
|
if (typeValue.match(/^boolean/g)) {
|
174
141
|
return false;
|
175
142
|
}
|
176
|
-
|
177
143
|
if (typeValue.match(/^null/g)) {
|
178
144
|
return null;
|
179
145
|
}
|
180
|
-
|
181
146
|
if (skipExampleIds && typeValue.match(/^string/g) && fallbackPropertyName.match(/id$/i)) {
|
182
147
|
return '';
|
183
148
|
}
|
184
|
-
|
185
149
|
if (typeValue.match(/^string/g)) {
|
186
150
|
if (schemaObj.pattern) {
|
187
151
|
const examplePattern = schemaObj.pattern.replace(/[+*](?![^\][]*[\]])/g, '{8}').replace(/\{\d*,(\d+)?\}/g, '{8}');
|
188
|
-
|
189
152
|
try {
|
190
153
|
return new _randexp.default(examplePattern).gen() || fallbackPropertyName || 'string';
|
191
154
|
} catch (error) {
|
192
155
|
return fallbackPropertyName || 'string';
|
193
156
|
}
|
194
157
|
}
|
195
|
-
|
196
158
|
if (schemaObj.format) {
|
197
159
|
switch (schemaObj.format.toLowerCase()) {
|
198
160
|
case 'url':
|
199
161
|
return 'https://example.com';
|
200
|
-
|
201
162
|
case 'uri':
|
202
163
|
return 'urn:namespace:type:example/resource';
|
203
|
-
|
204
164
|
case 'date':
|
205
165
|
return new Date().toISOString().split('T')[0];
|
206
|
-
|
207
166
|
case 'time':
|
208
167
|
return new Date().toISOString().split('T')[1];
|
209
|
-
|
210
168
|
case 'date-time':
|
211
169
|
return new Date().toISOString();
|
212
|
-
|
213
170
|
case 'duration':
|
214
171
|
return 'P3Y6M4DT12H30M5S';
|
215
172
|
// P=Period 3-Years 6-Months 4-Days 12-Hours 30-Minutes 5-Seconds
|
216
|
-
|
217
173
|
case 'email':
|
218
174
|
case 'idn-email':
|
219
175
|
return 'user@example.com';
|
220
|
-
|
221
176
|
case 'hostname':
|
222
177
|
case 'idn-hostname':
|
223
178
|
return 'www.example.com';
|
224
|
-
|
225
179
|
case 'ipv4':
|
226
180
|
return '192.168.0.1';
|
227
|
-
|
228
181
|
case 'ipv6':
|
229
182
|
return '2001:0db8:5b96:0000:0000:426f:8e17:642a';
|
230
|
-
|
231
183
|
case 'uuid':
|
232
184
|
return '4e0ba220-9575-11eb-a8b3-0242ac130003';
|
233
|
-
|
234
185
|
case 'byte':
|
235
186
|
// Byte type is actually a base64 encoded string: https://spec.openapis.org/oas/v3.0.0#data-types
|
236
187
|
return Buffer.from('example').toString('base64');
|
237
|
-
|
238
188
|
default:
|
239
189
|
return schemaObj.format;
|
240
190
|
}
|
241
191
|
} else {
|
242
192
|
return fallbackPropertyName || 'string';
|
243
193
|
}
|
244
|
-
}
|
245
|
-
|
246
|
-
|
194
|
+
}
|
195
|
+
// If type cannot be determined
|
247
196
|
return EXAMPLE_VALUE_FOR_MISSING_TYPE;
|
248
197
|
}
|
249
|
-
|
250
198
|
function duplicateExampleWithNewPropertyValues(objectExamples, propertyName, propertyValues) {
|
251
199
|
// Limit max number of property examples to 2 and limit the max number of examples to 10
|
252
200
|
return objectExamples.reduce((exampleList, example) => {
|
253
|
-
const examplesFromPropertyValues = propertyValues.slice(0, 2).map(value => ({
|
201
|
+
const examplesFromPropertyValues = propertyValues.slice(0, 2).map(value => ({
|
202
|
+
...(0, _lodash.default)(example),
|
254
203
|
[propertyName]: value
|
255
204
|
}));
|
256
205
|
return exampleList.concat(...examplesFromPropertyValues);
|
257
206
|
}, []).slice(0, 10);
|
258
207
|
}
|
259
|
-
|
260
208
|
function getExampleValuesFromSchema(schema, config = {}) {
|
261
209
|
// Wrap the top level so that the recursive object can treat it as a normal property and we'll hit the 'object' below, otherwise we'll never create the top level.
|
262
210
|
if (config.xml) {
|
@@ -267,30 +215,26 @@ function getExampleValuesFromSchema(schema, config = {}) {
|
|
267
215
|
} : schema, config);
|
268
216
|
return xmlResult.map(example => example[0]);
|
269
217
|
}
|
270
|
-
|
271
218
|
return getExampleValuesFromSchemaRecursive(schema, config);
|
272
|
-
}
|
273
|
-
|
219
|
+
}
|
274
220
|
|
221
|
+
// TODO: Support getting the `summary` from the examples object or the `title` from the schema object
|
275
222
|
function getExampleValuesFromSchemaRecursive(rawSchema, config = {}) {
|
276
223
|
var _rawSchema$items, _rawSchema$items$xml, _rawSchema$xml;
|
277
|
-
|
278
224
|
if (!rawSchema) {
|
279
225
|
return [];
|
280
|
-
}
|
281
|
-
|
226
|
+
}
|
282
227
|
|
228
|
+
// XML Support
|
283
229
|
const xmlAttributes = {};
|
284
230
|
const xmlTagProperties = [];
|
285
231
|
const {
|
286
232
|
prefix,
|
287
233
|
namespace
|
288
234
|
} = rawSchema.xml || {};
|
289
|
-
|
290
235
|
if (namespace) {
|
291
236
|
xmlAttributes[prefix ? `xmlns:${prefix}` : 'xmlns'] = namespace;
|
292
237
|
}
|
293
|
-
|
294
238
|
const nodeName = (rawSchema === null || rawSchema === void 0 ? void 0 : (_rawSchema$items = rawSchema.items) === null || _rawSchema$items === void 0 ? void 0 : (_rawSchema$items$xml = _rawSchema$items.xml) === null || _rawSchema$items$xml === void 0 ? void 0 : _rawSchema$items$xml.name) || (rawSchema === null || rawSchema === void 0 ? void 0 : (_rawSchema$xml = rawSchema.xml) === null || _rawSchema$xml === void 0 ? void 0 : _rawSchema$xml.name) || config.propertyName || 'root';
|
295
239
|
const overridePropertyName = prefix ? `${prefix}:${nodeName}` : nodeName;
|
296
240
|
const {
|
@@ -299,39 +243,31 @@ function getExampleValuesFromSchemaRecursive(rawSchema, config = {}) {
|
|
299
243
|
anyOf,
|
300
244
|
...schema
|
301
245
|
} = rawSchema;
|
302
|
-
|
303
246
|
if (allOf) {
|
304
247
|
const mergedAllOf = (0, _lodash2.default)({}, ...allOf, schema);
|
305
248
|
return getExampleValuesFromSchemaRecursive(mergedAllOf, config);
|
306
249
|
}
|
307
|
-
|
308
250
|
if (oneOf || anyOf) {
|
309
251
|
const examples = (oneOf || anyOf).map(s => getExampleValuesFromSchemaRecursive((0, _lodash2.default)({}, schema, s), config)).flat(1);
|
310
|
-
|
311
252
|
const hash = value => {
|
312
253
|
if (typeof value === 'object') {
|
313
254
|
return JSON.stringify(value);
|
314
255
|
}
|
315
|
-
|
316
256
|
return value;
|
317
257
|
};
|
318
|
-
|
319
258
|
const uniqueExamples = examples.reduce((acc, e) => {
|
320
259
|
acc[hash(e)] = e;
|
321
260
|
return acc;
|
322
261
|
}, {});
|
323
262
|
return Object.values(uniqueExamples);
|
324
263
|
}
|
325
|
-
|
326
264
|
return getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes, xmlTagProperties, overridePropertyName);
|
327
265
|
}
|
328
|
-
|
329
266
|
function getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes, xmlTagProperties, overridePropertyName) {
|
330
267
|
if (schema.type === 'array' || schema.items) {
|
331
268
|
if (!config.xml) {
|
332
269
|
return [getExampleValuesFromSchemaRecursive(schema.items || {}, config)];
|
333
270
|
}
|
334
|
-
|
335
271
|
if (!schema.xml || !schema.xml.wrapped) {
|
336
272
|
const arrayExamples = getExampleValuesFromSchemaRecursive(schema.items || {}, config);
|
337
273
|
xmlTagProperties.push({
|
@@ -341,8 +277,8 @@ function getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes,
|
|
341
277
|
});
|
342
278
|
return [xmlTagProperties];
|
343
279
|
}
|
344
|
-
|
345
|
-
|
280
|
+
const arrayExamples = getExampleValuesFromSchemaRecursive(schema.items || {}, {
|
281
|
+
...config,
|
346
282
|
propertyName: overridePropertyName
|
347
283
|
});
|
348
284
|
xmlTagProperties.push({
|
@@ -352,36 +288,29 @@ function getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes,
|
|
352
288
|
});
|
353
289
|
return [xmlTagProperties];
|
354
290
|
}
|
355
|
-
|
356
291
|
if (schema.type === 'object' || schema.properties) {
|
357
292
|
let objectExamples = [{}];
|
358
293
|
Object.keys(schema.properties || {}).forEach(propertyName => {
|
359
294
|
const innerSchema = schema.properties[propertyName];
|
360
|
-
|
361
295
|
if (innerSchema.deprecated) {
|
362
296
|
return;
|
363
297
|
}
|
364
|
-
|
365
298
|
if (innerSchema.readOnly && !config.includeReadOnly) {
|
366
299
|
return;
|
367
300
|
}
|
368
|
-
|
369
301
|
if (innerSchema.writeOnly && !config.includeWriteOnly) {
|
370
302
|
return;
|
371
303
|
}
|
372
|
-
|
373
|
-
|
304
|
+
const propertyExamples = getExampleValuesFromSchemaRecursive(innerSchema, {
|
305
|
+
...config,
|
374
306
|
propertyName
|
375
307
|
});
|
376
308
|
objectExamples = duplicateExampleWithNewPropertyValues(objectExamples, propertyName, propertyExamples);
|
377
|
-
|
378
309
|
if (innerSchema.xml && innerSchema.xml.namespace) {
|
379
310
|
xmlAttributes[innerSchema.xml.prefix ? `xmlns:${innerSchema.xml.prefix}` : 'xmlns'] = namespace;
|
380
311
|
}
|
381
|
-
|
382
312
|
const innerNodeName = innerSchema.xml && innerSchema.xml.name || propertyName || config.propertyName;
|
383
313
|
const innerOverridePropertyName = prefix ? `${prefix}:${innerNodeName}` : innerNodeName;
|
384
|
-
|
385
314
|
if (innerSchema.xml && innerSchema.xml.attribute) {
|
386
315
|
xmlAttributes[innerOverridePropertyName] = propertyExamples[0];
|
387
316
|
} else {
|
@@ -390,20 +319,16 @@ function getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes,
|
|
390
319
|
});
|
391
320
|
}
|
392
321
|
});
|
393
|
-
|
394
322
|
if (Object.keys(xmlAttributes).length) {
|
395
323
|
xmlTagProperties.push({
|
396
324
|
_attr: xmlAttributes
|
397
325
|
});
|
398
326
|
}
|
399
|
-
|
400
327
|
return config.xml ? [xmlTagProperties] : objectExamples;
|
401
328
|
}
|
402
|
-
|
403
329
|
const value = getSampleValueByType(schema, config.propertyName, config.skipExampleIds);
|
404
330
|
return [value];
|
405
331
|
}
|
406
|
-
|
407
332
|
function isPatternProperty(label) {
|
408
333
|
return label.match(/^<any-key>|<pattern:/);
|
409
334
|
}
|
@@ -415,13 +340,10 @@ function isPatternProperty(label) {
|
|
415
340
|
* @param {number} level - recursion level
|
416
341
|
* @param {string} suffix - used for suffixing property names to avoid duplicate props during object composition
|
417
342
|
*/
|
418
|
-
|
419
|
-
|
420
343
|
function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
421
344
|
if (!rawSchema) {
|
422
345
|
return undefined;
|
423
346
|
}
|
424
|
-
|
425
347
|
const {
|
426
348
|
allOf,
|
427
349
|
oneOf,
|
@@ -435,15 +357,12 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
435
357
|
const metadata = {
|
436
358
|
constraints: []
|
437
359
|
};
|
438
|
-
|
439
360
|
if (schema.uniqueItems) {
|
440
361
|
metadata.constraints.push('Requires unique items');
|
441
362
|
}
|
442
|
-
|
443
363
|
if (typeof schema.minItems === 'number' || typeof schema.maxItems === 'number') {
|
444
364
|
metadata.constraints.push(`Length: [${schema.minItems || 0}${schema.maxItems ? ', ' : '+'}${schema.maxItems || ''}]`);
|
445
365
|
}
|
446
|
-
|
447
366
|
if (allOf) {
|
448
367
|
// If allOf is an array of multiple elements, then all the keys makes a single object
|
449
368
|
const objWithAllProps = {};
|
@@ -470,10 +389,8 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
470
389
|
(anyOf || oneOf || []).forEach((v, index) => {
|
471
390
|
if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
|
472
391
|
const partialObj = schemaInObjectNotation(v, options);
|
473
|
-
|
474
392
|
if (partialObj) {
|
475
393
|
var _partialObj$Flags, _partialObj$Flags2;
|
476
|
-
|
477
394
|
objWithAnyOfProps[`::OPTION~${index + 1}${v.title ? `~${v.title}` : ''}`] = partialObj;
|
478
395
|
objWithAnyOfProps['::type'] = 'xxx-of-option';
|
479
396
|
readOnly = readOnly && ((_partialObj$Flags = partialObj['::flags']) === null || _partialObj$Flags === void 0 ? void 0 : _partialObj$Flags['🆁']);
|
@@ -481,7 +398,6 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
481
398
|
}
|
482
399
|
} else if (v.type === 'array' || v.items) {
|
483
400
|
var _partialObj$Flags3, _partialObj$Flags4;
|
484
|
-
|
485
401
|
const partialObj = schemaInObjectNotation(v, options);
|
486
402
|
objWithAnyOfProps[`::OPTION~${index + 1}${v.title ? `~${v.title}` : ''}`] = partialObj;
|
487
403
|
objWithAnyOfProps['::type'] = 'xxx-of-array';
|
@@ -489,10 +405,8 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
489
405
|
writeOnly = writeOnly && ((_partialObj$Flags4 = partialObj['::flags']) === null || _partialObj$Flags4 === void 0 ? void 0 : _partialObj$Flags4['🆆']);
|
490
406
|
} else {
|
491
407
|
const typeInfo = getTypeInfo(v, options);
|
492
|
-
|
493
408
|
if (typeInfo !== null && typeInfo !== void 0 && typeInfo.type) {
|
494
409
|
var _objWithAnyOfProps$, _objWithAnyOfProps$2;
|
495
|
-
|
496
410
|
const prop = `::OPTION~${index + 1}${v.title ? `~${v.title}` : ''}`;
|
497
411
|
objWithAnyOfProps[prop] = `${typeInfo.html}`;
|
498
412
|
objWithAnyOfProps['::type'] = 'xxx-of-option';
|
@@ -503,12 +417,11 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
503
417
|
});
|
504
418
|
const obj = schemaInObjectNotation(schema, options, 0);
|
505
419
|
const resultObj = typeof obj === 'object' && !Array.isArray(obj) ? obj : {};
|
506
|
-
|
507
420
|
if (Object.keys(objWithAnyOfProps).length) {
|
508
421
|
resultObj[anyOf ? `::ANY~OF ${suffix}` : `::ONE~OF ${suffix}`] = objWithAnyOfProps;
|
509
422
|
}
|
510
|
-
|
511
|
-
resultObj['::type'] = 'object';
|
423
|
+
resultObj['::link'] = schema.title;
|
424
|
+
resultObj['::type'] = schema.title || 'object';
|
512
425
|
resultObj['::flags'] = {
|
513
426
|
'🆁': readOnly && '🆁',
|
514
427
|
'🆆': writeOnly && '🆆'
|
@@ -520,9 +433,9 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
520
433
|
} else if (Array.isArray(propertyType)) {
|
521
434
|
const obj = {
|
522
435
|
'::type': ''
|
523
|
-
};
|
436
|
+
};
|
437
|
+
// When a property has multiple types, then check further if any of the types are array or object, if yes then modify the schema using one-of
|
524
438
|
// Clone the schema - as it will be modified to replace multi-data-types with one-of;
|
525
|
-
|
526
439
|
const subSchema = JSON.parse(JSON.stringify(schema));
|
527
440
|
const primitiveType = [];
|
528
441
|
const complexTypes = [];
|
@@ -541,24 +454,22 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
541
454
|
}
|
542
455
|
});
|
543
456
|
let multiPrimitiveTypes;
|
544
|
-
|
545
457
|
if (primitiveType.length > 0) {
|
546
458
|
subSchema.type = primitiveType.join('┃');
|
547
459
|
multiPrimitiveTypes = getTypeInfo(subSchema, options);
|
548
|
-
|
549
460
|
if (complexTypes.length === 0) {
|
550
461
|
var _multiPrimitiveTypes;
|
551
|
-
|
552
462
|
return `${((_multiPrimitiveTypes = multiPrimitiveTypes) === null || _multiPrimitiveTypes === void 0 ? void 0 : _multiPrimitiveTypes.html) || ''}`;
|
553
463
|
}
|
554
464
|
}
|
555
|
-
|
556
465
|
if (complexTypes.length > 0) {
|
466
|
+
obj['::link'] = schema.title;
|
557
467
|
obj['::type'] = 'object';
|
558
468
|
const multiTypeOptions = {
|
559
469
|
'::type': 'xxx-of-option'
|
560
|
-
};
|
470
|
+
};
|
561
471
|
|
472
|
+
// Generate ONE-OF options for complexTypes
|
562
473
|
complexTypes.forEach((v, i) => {
|
563
474
|
if (v === 'null') {
|
564
475
|
multiTypeOptions[`::OPTION~${i + 1}`] = 'NULL~|~~|~~|~~|~~|~~|~~|~~|~';
|
@@ -575,21 +486,19 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
575
486
|
'🆁': schema.readOnly && '🆁',
|
576
487
|
'🆆': schema.writeOnly && '🆆'
|
577
488
|
},
|
578
|
-
'::
|
489
|
+
'::link': schema.title,
|
490
|
+
'::type': schema.title || 'object',
|
579
491
|
'::deprecated': schema.deprecated || false,
|
580
492
|
'::metadata': metadata
|
581
493
|
};
|
582
|
-
|
583
494
|
for (const key in schemaProperties) {
|
584
495
|
var _schema$required;
|
585
|
-
|
586
496
|
if (!schema.deprecated && !schemaProperties[key].deprecated && (_schema$required = schema.required) !== null && _schema$required !== void 0 && _schema$required.includes(key)) {
|
587
497
|
objTypeOption[`${key}*`] = schemaInObjectNotation(schemaProperties[key], options, level + 1);
|
588
498
|
} else {
|
589
499
|
objTypeOption[key] = schemaInObjectNotation(schemaProperties[key], options, level + 1);
|
590
500
|
}
|
591
501
|
}
|
592
|
-
|
593
502
|
multiTypeOptions[`::OPTION~${i + 1}`] = objTypeOption;
|
594
503
|
} else if (v === 'array') {
|
595
504
|
multiTypeOptions[`::OPTION~${i + 1}`] = {
|
@@ -599,6 +508,7 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
599
508
|
'🆁': schema.readOnly && '🆁',
|
600
509
|
'🆆': schema.writeOnly && '🆆'
|
601
510
|
},
|
511
|
+
'::link': arrayItemsSchema.title || schema.title,
|
602
512
|
'::type': 'array',
|
603
513
|
// Array properties are read from the ::props object instead of reading from the keys of this object
|
604
514
|
// '::props': schemaInObjectNotation(Object.assign({ deprecated: schema.deprecated, readOnly: schema.readOnly, writeOnly: schema.writeOnly }, arrayItemsSchema), options, (level + 1)),
|
@@ -611,7 +521,6 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
611
521
|
multiTypeOptions[`::OPTION~${complexTypes.length + 1}`] = multiPrimitiveTypes && multiPrimitiveTypes.html || '';
|
612
522
|
obj['::ONE~OF'] = multiTypeOptions;
|
613
523
|
}
|
614
|
-
|
615
524
|
return obj;
|
616
525
|
} else if (propertyType === 'object' || schemaProperties) {
|
617
526
|
const obj = {
|
@@ -623,28 +532,24 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
623
532
|
'🆁': schema.readOnly && '🆁',
|
624
533
|
'🆆': schema.writeOnly && '🆆'
|
625
534
|
};
|
626
|
-
obj['::
|
535
|
+
obj['::link'] = schema.title;
|
536
|
+
obj['::type'] = schema.title || 'object';
|
627
537
|
obj['::deprecated'] = schema.deprecated || false;
|
628
538
|
obj['::metadata'] = metadata;
|
629
|
-
|
630
539
|
for (const key in schemaProperties) {
|
631
540
|
var _schema$required2;
|
632
|
-
|
633
541
|
if (!schema.deprecated && !schemaProperties[key].deprecated && (_schema$required2 = schema.required) !== null && _schema$required2 !== void 0 && _schema$required2.includes(key)) {
|
634
542
|
obj[`${key}*`] = schemaInObjectNotation(schemaProperties[key], options, level + 1);
|
635
543
|
} else {
|
636
544
|
obj[key] = schemaInObjectNotation(schemaProperties[key], options, level + 1);
|
637
545
|
}
|
638
546
|
}
|
639
|
-
|
640
547
|
for (const key in schemaPatternProperties) {
|
641
548
|
obj[`<pattern: ${key}>`] = schemaInObjectNotation(schemaPatternProperties[key], options, level + 1);
|
642
549
|
}
|
643
|
-
|
644
550
|
if (schema.additionalProperties) {
|
645
551
|
obj['<any-key>'] = schemaInObjectNotation(schema.additionalProperties, options);
|
646
552
|
}
|
647
|
-
|
648
553
|
return obj;
|
649
554
|
} else if (propertyType === 'array' || arrayItemsSchema) {
|
650
555
|
// If Array
|
@@ -657,44 +562,40 @@ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
|
|
657
562
|
'🆁': schema.readOnly && '🆁',
|
658
563
|
'🆆': schema.writeOnly && '🆆'
|
659
564
|
};
|
565
|
+
obj['::link'] = arrayItemsSchema.title || schema.title;
|
660
566
|
obj['::type'] = 'array';
|
661
567
|
obj['::deprecated'] = schema.deprecated || false;
|
662
|
-
obj['::metadata'] = metadata;
|
568
|
+
obj['::metadata'] = metadata;
|
569
|
+
// Array properties are read from the ::props object instead of reading from the keys of this object
|
663
570
|
// Use type: undefined to prevent schema recursion by passing array from the parent to the next loop. arrayItemsSchema should have had type defined but it doesn't.
|
664
|
-
|
665
571
|
obj['::props'] = schemaInObjectNotation(Object.assign({}, schema, {
|
666
572
|
type: undefined
|
667
573
|
}, arrayItemsSchema), options, level + 1);
|
668
|
-
|
669
574
|
if (arrayItemsSchema !== null && arrayItemsSchema !== void 0 && arrayItemsSchema.items) {
|
670
575
|
obj['::array-type'] = arrayItemsSchema.items.type;
|
671
576
|
}
|
672
|
-
|
673
577
|
return obj;
|
674
578
|
}
|
675
|
-
|
676
579
|
const typeObj = getTypeInfo(schema, options);
|
677
580
|
return `${(typeObj === null || typeObj === void 0 ? void 0 : typeObj.html) || ''}`;
|
678
581
|
}
|
679
|
-
/* Create Example object */
|
680
|
-
|
681
582
|
|
583
|
+
/* Create Example object */
|
682
584
|
function generateExample(examples, example, schema, rawMimeType, includeReadOnly = true, includeWriteOnly = true, outputType, skipExampleIds = false) {
|
683
585
|
const mimeType = rawMimeType || 'application/json';
|
684
|
-
const finalExamples = [];
|
586
|
+
const finalExamples = [];
|
685
587
|
|
588
|
+
// First check if examples is provided
|
686
589
|
if (examples) {
|
687
590
|
for (const eg in examples) {
|
688
591
|
let egContent = '';
|
689
592
|
let egFormat = 'json';
|
690
|
-
|
691
593
|
if (mimeType.toLowerCase().includes('json')) {
|
692
594
|
if (outputType === 'text') {
|
693
595
|
egContent = typeof examples[eg].value === 'string' ? examples[eg].value : JSON.stringify(examples[eg].value, undefined, 2);
|
694
596
|
egFormat = 'text';
|
695
597
|
} else {
|
696
598
|
egContent = examples[eg].value;
|
697
|
-
|
698
599
|
if (typeof examples[eg].value === 'string') {
|
699
600
|
try {
|
700
601
|
const fixedJsonString = examples[eg].value.replace(/([\w]+)(:)/g, '"$1"$2').replace(/'/g, '"');
|
@@ -710,7 +611,6 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
710
611
|
egContent = examples[eg].value;
|
711
612
|
egFormat = 'text';
|
712
613
|
}
|
713
|
-
|
714
614
|
finalExamples.push({
|
715
615
|
exampleId: eg,
|
716
616
|
exampleSummary: examples[eg].summary || '',
|
@@ -723,7 +623,6 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
723
623
|
} else if (example) {
|
724
624
|
let egContent = '';
|
725
625
|
let egFormat = 'json';
|
726
|
-
|
727
626
|
if (mimeType.toLowerCase().includes('json')) {
|
728
627
|
if (outputType === 'text') {
|
729
628
|
egContent = typeof example === 'string' ? example : JSON.stringify(example, undefined, 2);
|
@@ -744,7 +643,6 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
744
643
|
egContent = example;
|
745
644
|
egFormat = 'text';
|
746
645
|
}
|
747
|
-
|
748
646
|
finalExamples.push({
|
749
647
|
exampleId: 'Example',
|
750
648
|
exampleSummary: '',
|
@@ -753,13 +651,12 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
753
651
|
exampleValue: egContent,
|
754
652
|
exampleFormat: egFormat
|
755
653
|
});
|
756
|
-
}
|
757
|
-
|
654
|
+
}
|
758
655
|
|
656
|
+
// If schema-level examples are not provided then generate one based on the schema field types
|
759
657
|
if (finalExamples.length) {
|
760
658
|
return finalExamples;
|
761
659
|
}
|
762
|
-
|
763
660
|
if (schema !== null && schema !== void 0 && schema.example) {
|
764
661
|
// Note: schema.examples (plurals) is not allowed as per spec
|
765
662
|
return [{
|
@@ -771,7 +668,6 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
771
668
|
exampleFormat: mimeType.toLowerCase().includes('json') && typeof schema.example === 'object' ? 'json' : 'text'
|
772
669
|
}];
|
773
670
|
}
|
774
|
-
|
775
671
|
const config = {
|
776
672
|
includeReadOnly,
|
777
673
|
includeWriteOnly,
|
@@ -779,7 +675,6 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
779
675
|
xml: mimeType.toLowerCase().includes('xml')
|
780
676
|
};
|
781
677
|
const samples = getExampleValuesFromSchema(schema, config);
|
782
|
-
|
783
678
|
if (!samples || !mimeType.toLowerCase().includes('json') && !mimeType.toLowerCase().includes('text') && !mimeType.toLowerCase().includes('*/*') && !mimeType.toLowerCase().includes('xml')) {
|
784
679
|
return [{
|
785
680
|
exampleId: 'Example',
|
@@ -790,10 +685,8 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
790
685
|
exampleFormat: 'text'
|
791
686
|
}];
|
792
687
|
}
|
793
|
-
|
794
688
|
return samples.map((sample, sampleCounter) => {
|
795
689
|
let exampleValue = '';
|
796
|
-
|
797
690
|
if (mimeType.toLowerCase().includes('xml')) {
|
798
691
|
exampleValue = (0, _xml.default)(sample, {
|
799
692
|
declaration: true,
|
@@ -802,7 +695,6 @@ function generateExample(examples, example, schema, rawMimeType, includeReadOnly
|
|
802
695
|
} else {
|
803
696
|
exampleValue = outputType === 'text' ? JSON.stringify(sample, null, 8) : sample;
|
804
697
|
}
|
805
|
-
|
806
698
|
return {
|
807
699
|
exampleId: `Example-${sampleCounter}`,
|
808
700
|
exampleSummary: '',
|