openapi-explorer 0.9.310 → 0.9.314
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/CHANGELOG.md +1 -0
- package/dist/{openapi-explorer.min.js → browser/openapi-explorer.min.js} +3 -3
- package/dist/{openapi-explorer.min.js.map → browser/openapi-explorer.min.js.map} +0 -0
- package/dist/es/components/api-request.js +936 -0
- package/dist/es/components/api-response.js +184 -0
- package/dist/es/components/json-tree.js +67 -0
- package/{src → dist/es}/components/mime-types.js +11 -17
- package/dist/es/components/schema-table.js +156 -0
- package/dist/es/components/schema-tree.js +191 -0
- package/dist/es/components/tag-input.js +67 -0
- package/{src → dist/es}/openapi-explorer-oauth-handler.js +2 -2
- package/{src → dist/es}/openapi-explorer.js +364 -371
- package/dist/es/styles/advanced-search-styles.js +2 -0
- package/dist/es/styles/api-request-styles.js +2 -0
- package/dist/es/styles/border-styles.js +2 -0
- package/dist/es/styles/endpoint-styles.js +2 -0
- package/dist/es/styles/flex-styles.js +2 -0
- package/dist/es/styles/font-styles.js +2 -0
- package/dist/es/styles/info-styles.js +2 -0
- package/dist/es/styles/input-styles.js +4 -0
- package/dist/es/styles/nav-styles.js +2 -0
- package/dist/es/styles/prism-styles.js +2 -0
- package/dist/es/styles/schema-styles.js +2 -0
- package/dist/es/styles/tab-styles.js +2 -0
- package/dist/es/styles/table-styles.js +2 -0
- package/dist/es/templates/advance-search-template.js +37 -0
- package/dist/es/templates/callback-template.js +7 -0
- package/dist/es/templates/code-samples-template.js +26 -0
- package/dist/es/templates/components-template.js +17 -0
- package/dist/es/templates/endpoint-template.js +94 -0
- package/dist/es/templates/expanded-endpoint-template.js +32 -0
- package/{src → dist/es}/templates/focused-endpoint-template.js +15 -15
- package/dist/es/templates/navbar-template.js +46 -0
- package/dist/es/templates/overview-template.js +9 -0
- package/dist/es/templates/responsiveViewMainBodyTemplate.js +30 -0
- package/dist/es/templates/security-scheme-template.js +330 -0
- package/dist/es/templates/server-template.js +42 -0
- package/{src → dist/es}/utils/color-utils.js +53 -16
- package/{src → dist/es}/utils/common-utils.js +18 -18
- package/{src → dist/es}/utils/schema-utils.js +248 -124
- package/{src → dist/es}/utils/spec-parser.js +112 -71
- package/dist/es/utils/theme.js +75 -0
- package/{src → dist/es}/utils/xml/xml.js +41 -38
- package/dist/lib/components/api-request.js +957 -0
- package/dist/lib/components/api-response.js +206 -0
- package/dist/lib/components/json-tree.js +82 -0
- package/dist/lib/components/mime-types.js +70 -0
- package/dist/lib/components/schema-table.js +170 -0
- package/dist/lib/components/schema-tree.js +206 -0
- package/dist/lib/components/tag-input.js +76 -0
- package/dist/lib/openapi-explorer-oauth-handler.js +19 -0
- package/dist/lib/openapi-explorer.js +817 -0
- package/dist/lib/styles/advanced-search-styles.js +10 -0
- package/dist/lib/styles/api-request-styles.js +10 -0
- package/dist/lib/styles/border-styles.js +10 -0
- package/dist/lib/styles/endpoint-styles.js +10 -0
- package/dist/lib/styles/flex-styles.js +10 -0
- package/dist/lib/styles/font-styles.js +10 -0
- package/dist/lib/styles/info-styles.js +10 -0
- package/dist/lib/styles/input-styles.js +11 -0
- package/dist/lib/styles/nav-styles.js +10 -0
- package/dist/lib/styles/prism-styles.js +10 -0
- package/dist/lib/styles/schema-styles.js +10 -0
- package/dist/lib/styles/tab-styles.js +10 -0
- package/dist/lib/styles/table-styles.js +10 -0
- package/dist/lib/templates/advance-search-template.js +42 -0
- package/dist/lib/templates/callback-template.js +12 -0
- package/dist/lib/templates/code-samples-template.js +36 -0
- package/dist/lib/templates/components-template.js +27 -0
- package/dist/lib/templates/endpoint-template.js +111 -0
- package/dist/lib/templates/expanded-endpoint-template.js +48 -0
- package/dist/lib/templates/focused-endpoint-template.js +95 -0
- package/dist/lib/templates/navbar-template.js +54 -0
- package/dist/lib/templates/overview-template.js +16 -0
- package/dist/lib/templates/responsiveViewMainBodyTemplate.js +47 -0
- package/dist/lib/templates/security-scheme-template.js +342 -0
- package/dist/lib/templates/server-template.js +49 -0
- package/dist/lib/utils/color-utils.js +112 -0
- package/dist/lib/utils/common-utils.js +156 -0
- package/dist/lib/utils/schema-utils.js +743 -0
- package/dist/lib/utils/spec-parser.js +361 -0
- package/dist/lib/utils/theme.js +84 -0
- package/dist/lib/utils/xml/xml.js +239 -0
- package/package.json +19 -6
- package/dist/openapi-explorer.min.js.LICENSE.txt +0 -71
- package/dist/openapi-explorer.min.js.LICENSE.txt.gz +0 -0
- package/dist/openapi-explorer.min.js.gz +0 -0
- package/dist/openapi-explorer.min.js.map.gz +0 -0
- package/dist/report.html +0 -38
- package/src/components/api-request.js +0 -1244
- package/src/components/api-response.js +0 -340
- package/src/components/json-tree.js +0 -129
- package/src/components/schema-table.js +0 -250
- package/src/components/schema-tree.js +0 -280
- package/src/components/tag-input.js +0 -109
- package/src/styles/advanced-search-styles.js +0 -84
- package/src/styles/api-request-styles.js +0 -111
- package/src/styles/border-styles.js +0 -24
- package/src/styles/css/main.css +0 -24
- package/src/styles/endpoint-styles.js +0 -222
- package/src/styles/flex-styles.js +0 -15
- package/src/styles/font-styles.js +0 -266
- package/src/styles/info-styles.js +0 -20
- package/src/styles/input-styles.js +0 -236
- package/src/styles/nav-styles.js +0 -141
- package/src/styles/prism-styles.js +0 -107
- package/src/styles/schema-styles.js +0 -121
- package/src/styles/tab-styles.js +0 -44
- package/src/styles/table-styles.js +0 -48
- package/src/templates/advance-search-template.js +0 -81
- package/src/templates/callback-template.js +0 -63
- package/src/templates/code-samples-template.js +0 -35
- package/src/templates/components-template.js +0 -43
- package/src/templates/endpoint-template.js +0 -175
- package/src/templates/expanded-endpoint-template.js +0 -104
- package/src/templates/navbar-template.js +0 -175
- package/src/templates/overview-template.js +0 -58
- package/src/templates/responsiveViewMainBodyTemplate.js +0 -72
- package/src/templates/security-scheme-template.js +0 -487
- package/src/templates/server-template.js +0 -106
- package/src/utils/theme.js +0 -163
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import cloneDeep from 'lodash.clonedeep';
|
|
2
2
|
import { expandN } from 'regex-to-strings';
|
|
3
|
-
import xmlFormatter from './xml/xml';
|
|
3
|
+
import xmlFormatter from './xml/xml'; // When the type is not known for a property set the displayed type to be this:
|
|
4
4
|
|
|
5
|
-
// When the type is not known for a property set the displayed type to be this:
|
|
6
5
|
const IS_MISSING_TYPE_INFO_TYPE = '';
|
|
7
|
-
|
|
8
6
|
/* Generates an schema object containing type and constraint info */
|
|
7
|
+
|
|
9
8
|
export function getTypeInfo(schema) {
|
|
10
9
|
if (!schema) {
|
|
11
10
|
return undefined;
|
|
12
11
|
}
|
|
12
|
+
|
|
13
13
|
let dataType = '';
|
|
14
14
|
let constraint = '';
|
|
15
15
|
|
|
@@ -18,8 +18,9 @@ export function getTypeInfo(schema) {
|
|
|
18
18
|
const schemaNode = schema.$ref.substring(n + 1);
|
|
19
19
|
dataType = `{recursive: ${schemaNode}} `;
|
|
20
20
|
} else if (schema.type) {
|
|
21
|
-
const arraySchema = Array.isArray(schema.type) ? schema.type :
|
|
22
|
-
dataType = Array.isArray(arraySchema) ? arraySchema.filter(
|
|
21
|
+
const arraySchema = Array.isArray(schema.type) ? schema.type : typeof schema.type === 'string' ? schema.type.split('┃') : schema.type;
|
|
22
|
+
dataType = Array.isArray(arraySchema) ? arraySchema.filter(s => s !== 'null').join('┃') : schema.type;
|
|
23
|
+
|
|
23
24
|
if (schema.format || schema.enum) {
|
|
24
25
|
dataType = dataType.replace('string', schema.enum ? 'enum' : schema.format);
|
|
25
26
|
}
|
|
@@ -30,48 +31,55 @@ export function getTypeInfo(schema) {
|
|
|
30
31
|
const info = {
|
|
31
32
|
type: dataType,
|
|
32
33
|
format: schema.format || '',
|
|
33
|
-
pattern:
|
|
34
|
+
pattern: schema.pattern && !schema.enum ? schema.pattern : '',
|
|
34
35
|
readOrWriteOnly: schema.readOnly && '🆁' || schema.writeOnly && '🆆' || '',
|
|
35
36
|
deprecated: !!schema.deprecated,
|
|
36
|
-
example: Array.isArray(schema.example) ? schema.example :
|
|
37
|
+
example: Array.isArray(schema.example) ? schema.example : typeof schema.example !== 'undefined' ? `${schema.example}` : '',
|
|
37
38
|
default: schema.default || '',
|
|
38
39
|
title: schema.title || '',
|
|
39
40
|
description: schema.description || '',
|
|
40
41
|
constraint: '',
|
|
41
42
|
allowedValues: '',
|
|
42
43
|
arrayType: '',
|
|
43
|
-
html: ''
|
|
44
|
+
html: ''
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
if (info.type === '{recursive}') {
|
|
47
48
|
info.description = schema.$ref.substring(schema.$ref.lastIndexOf('/') + 1);
|
|
48
49
|
} else if (info.type === IS_MISSING_TYPE_INFO_TYPE) {
|
|
49
50
|
info.description = info.description || '';
|
|
50
|
-
}
|
|
51
|
+
} // Set Allowed Values
|
|
52
|
+
|
|
51
53
|
|
|
52
|
-
// Set Allowed Values
|
|
53
54
|
info.allowedValues = Array.isArray(schema.enum) ? schema.enum.join('┃') : '';
|
|
55
|
+
|
|
54
56
|
if (dataType === 'array' && schema.items) {
|
|
55
|
-
|
|
56
|
-
const arrayItemDefault = schema.items.default ?? '';
|
|
57
|
+
var _schema$items$default;
|
|
57
58
|
|
|
59
|
+
const arrayItemType = schema.items.type;
|
|
60
|
+
const arrayItemDefault = (_schema$items$default = schema.items.default) !== null && _schema$items$default !== void 0 ? _schema$items$default : '';
|
|
58
61
|
info.arrayType = `${schema.type} of ${Array.isArray(arrayItemType) ? arrayItemType.join('') : arrayItemType}`;
|
|
59
62
|
info.default = arrayItemDefault;
|
|
60
63
|
info.allowedValues = Array.isArray(schema.items.enum) ? schema.items.enum.join('┃') : '';
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
if (dataType.match(/integer|number/g)) {
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
var _schema$minimum, _schema$maximum;
|
|
68
|
+
|
|
69
|
+
const minimum = (_schema$minimum = schema.minimum) !== null && _schema$minimum !== void 0 ? _schema$minimum : schema.exclusiveMinimum;
|
|
70
|
+
const maximum = (_schema$maximum = schema.maximum) !== null && _schema$maximum !== void 0 ? _schema$maximum : schema.exclusiveMaximum;
|
|
66
71
|
const leftBound = schema.minimum !== undefined ? '[' : '(';
|
|
67
72
|
const rightBound = schema.maximum !== undefined ? ']' : ')';
|
|
73
|
+
|
|
68
74
|
if (typeof minimum === 'number' || typeof maximum === 'number') {
|
|
69
|
-
constraint = `Range: ${leftBound}${minimum
|
|
75
|
+
constraint = `Range: ${leftBound}${minimum !== null && minimum !== void 0 ? minimum : ''},${maximum !== null && maximum !== void 0 ? maximum : ''}${rightBound}`;
|
|
70
76
|
}
|
|
77
|
+
|
|
71
78
|
if (schema.multipleOf !== undefined) {
|
|
72
79
|
constraint += `${constraint ? ', ' : ''}Multiples: ${schema.multipleOf}`;
|
|
73
80
|
}
|
|
74
81
|
}
|
|
82
|
+
|
|
75
83
|
if (dataType.match(/string/g)) {
|
|
76
84
|
if (schema.minLength !== undefined && schema.maxLength !== undefined) {
|
|
77
85
|
constraint += `Min length: ${schema.minLength}, Max length: ${schema.maxLength}`;
|
|
@@ -81,6 +89,7 @@ export function getTypeInfo(schema) {
|
|
|
81
89
|
constraint += `Max length: ${schema.maxLength}`;
|
|
82
90
|
}
|
|
83
91
|
}
|
|
92
|
+
|
|
84
93
|
info.constraint = constraint;
|
|
85
94
|
info.html = JSON.stringify({
|
|
86
95
|
type: info.type,
|
|
@@ -95,95 +104,131 @@ export function getTypeInfo(schema) {
|
|
|
95
104
|
});
|
|
96
105
|
return info;
|
|
97
106
|
}
|
|
98
|
-
|
|
99
107
|
export function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleStrings) {
|
|
108
|
+
var _schemaObj$type;
|
|
109
|
+
|
|
100
110
|
const example = schemaObj.examples ? schemaObj.examples[0] : schemaObj.example;
|
|
101
|
-
if (example === '') { return ''; }
|
|
102
|
-
if (example === null) { return null; }
|
|
103
|
-
if (example === 0) { return 0; }
|
|
104
|
-
if (skipExampleStrings && typeof example === 'string') { return ''; }
|
|
105
|
-
if (example) { return example; }
|
|
106
111
|
|
|
107
|
-
if (
|
|
112
|
+
if (example === '') {
|
|
113
|
+
return '';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (example === null) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (example === 0) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (skipExampleStrings && typeof example === 'string') {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (example) {
|
|
129
|
+
return example;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (schemaObj.default) {
|
|
133
|
+
return schemaObj.default;
|
|
134
|
+
}
|
|
108
135
|
|
|
109
136
|
if (Object.keys(schemaObj).length === 0) {
|
|
110
137
|
return null;
|
|
111
138
|
}
|
|
139
|
+
|
|
112
140
|
if (schemaObj.$ref) {
|
|
113
141
|
// Indicates a Circular ref
|
|
114
142
|
return schemaObj.$ref;
|
|
115
143
|
}
|
|
116
|
-
|
|
144
|
+
|
|
145
|
+
const typeValue = Array.isArray(schemaObj.type) ? schemaObj.type.filter(t => t !== 'null')[0] : (_schemaObj$type = schemaObj.type) !== null && _schemaObj$type !== void 0 ? _schemaObj$type : '';
|
|
117
146
|
|
|
118
147
|
if (typeValue.match(/^integer|^number/g)) {
|
|
119
148
|
const multipleOf = Number.isNaN(Number(schemaObj.multipleOf)) ? undefined : Number(schemaObj.multipleOf);
|
|
120
149
|
const maximum = Number.isNaN(Number(schemaObj.maximum)) ? undefined : Number(schemaObj.maximum);
|
|
121
|
-
const minimumPossibleVal = Number.isNaN(Number(schemaObj.minimum))
|
|
122
|
-
|
|
123
|
-
? maximum || 0
|
|
124
|
-
: Number(schemaObj.exclusiveMinimum) + (typeValue.startsWith('integer') ? 1 : 0.001)
|
|
125
|
-
: Number(schemaObj.minimum);
|
|
126
|
-
const finalVal = multipleOf
|
|
127
|
-
? multipleOf >= minimumPossibleVal
|
|
128
|
-
? multipleOf
|
|
129
|
-
: minimumPossibleVal % multipleOf === 0
|
|
130
|
-
? minimumPossibleVal
|
|
131
|
-
: Math.ceil(minimumPossibleVal / multipleOf) * multipleOf
|
|
132
|
-
: minimumPossibleVal;
|
|
150
|
+
const minimumPossibleVal = Number.isNaN(Number(schemaObj.minimum)) ? Number.isNaN(Number(schemaObj.exclusiveMinimum)) ? maximum || 0 : Number(schemaObj.exclusiveMinimum) + (typeValue.startsWith('integer') ? 1 : 0.001) : Number(schemaObj.minimum);
|
|
151
|
+
const finalVal = multipleOf ? multipleOf >= minimumPossibleVal ? multipleOf : minimumPossibleVal % multipleOf === 0 ? minimumPossibleVal : Math.ceil(minimumPossibleVal / multipleOf) * multipleOf : minimumPossibleVal;
|
|
133
152
|
return finalVal;
|
|
134
153
|
}
|
|
135
|
-
|
|
136
|
-
if (typeValue.match(/^
|
|
137
|
-
|
|
154
|
+
|
|
155
|
+
if (typeValue.match(/^boolean/g)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (typeValue.match(/^null/g)) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (skipExampleStrings && typeValue.match(/^string/g)) {
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
166
|
+
|
|
138
167
|
if (typeValue.match(/^string/g)) {
|
|
139
|
-
if (schemaObj.enum) {
|
|
168
|
+
if (schemaObj.enum) {
|
|
169
|
+
return schemaObj.enum[0];
|
|
170
|
+
}
|
|
171
|
+
|
|
140
172
|
if (schemaObj.pattern) {
|
|
141
173
|
const examplePattern = schemaObj.pattern.replace(/[+*](?![^\][]*[\]])/g, '{8}').replace(/\{\d*,(\d+)?\}/g, '{8}');
|
|
142
174
|
return expandN(examplePattern, 1)[0] || fallbackPropertyName || 'string';
|
|
143
175
|
}
|
|
176
|
+
|
|
144
177
|
if (schemaObj.format) {
|
|
145
178
|
switch (schemaObj.format.toLowerCase()) {
|
|
146
179
|
case 'url':
|
|
147
180
|
return 'https://example.com';
|
|
181
|
+
|
|
148
182
|
case 'uri':
|
|
149
183
|
return 'urn:namespace:type:example/resource';
|
|
184
|
+
|
|
150
185
|
case 'date':
|
|
151
|
-
return
|
|
186
|
+
return new Date().toISOString().split('T')[0];
|
|
187
|
+
|
|
152
188
|
case 'time':
|
|
153
|
-
return
|
|
189
|
+
return new Date().toISOString().split('T')[1];
|
|
190
|
+
|
|
154
191
|
case 'date-time':
|
|
155
|
-
return
|
|
192
|
+
return new Date().toISOString();
|
|
193
|
+
|
|
156
194
|
case 'duration':
|
|
157
|
-
return 'P3Y6M4DT12H30M5S';
|
|
195
|
+
return 'P3Y6M4DT12H30M5S';
|
|
196
|
+
// P=Period 3-Years 6-Months 4-Days 12-Hours 30-Minutes 5-Seconds
|
|
197
|
+
|
|
158
198
|
case 'email':
|
|
159
199
|
case 'idn-email':
|
|
160
200
|
return 'user@example.com';
|
|
201
|
+
|
|
161
202
|
case 'hostname':
|
|
162
203
|
case 'idn-hostname':
|
|
163
204
|
return 'www.example.com';
|
|
205
|
+
|
|
164
206
|
case 'ipv4':
|
|
165
207
|
return '192.168.0.1';
|
|
208
|
+
|
|
166
209
|
case 'ipv6':
|
|
167
210
|
return '2001:0db8:5b96:0000:0000:426f:8e17:642a';
|
|
211
|
+
|
|
168
212
|
case 'uuid':
|
|
169
213
|
return '4e0ba220-9575-11eb-a8b3-0242ac130003';
|
|
214
|
+
|
|
170
215
|
default:
|
|
171
216
|
return schemaObj.format;
|
|
172
217
|
}
|
|
173
218
|
} else {
|
|
174
219
|
return fallbackPropertyName || 'string';
|
|
175
220
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
221
|
+
} // If type cannot be determined
|
|
222
|
+
|
|
223
|
+
|
|
178
224
|
return '?';
|
|
179
225
|
}
|
|
180
226
|
|
|
181
227
|
function duplicateExampleWithNewPropertyValues(objectExamples, propertyName, propertyValues) {
|
|
182
228
|
// Limit max number of property examples to 2 and limit the max number of examples to 10
|
|
183
229
|
return objectExamples.reduce((exampleList, example) => {
|
|
184
|
-
const examplesFromPropertyValues = propertyValues.slice(0, 2).map(
|
|
185
|
-
|
|
186
|
-
[propertyName]: value,
|
|
230
|
+
const examplesFromPropertyValues = propertyValues.slice(0, 2).map(value => ({ ...cloneDeep(example),
|
|
231
|
+
[propertyName]: value
|
|
187
232
|
}));
|
|
188
233
|
return exampleList.concat(...examplesFromPropertyValues);
|
|
189
234
|
}, []).slice(0, 10);
|
|
@@ -192,25 +237,34 @@ function duplicateExampleWithNewPropertyValues(objectExamples, propertyName, pro
|
|
|
192
237
|
export function getExampleValuesFromSchema(schema, config = {}) {
|
|
193
238
|
// 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.
|
|
194
239
|
if (config.xml) {
|
|
195
|
-
const xmlResult = getExampleValuesFromSchemaRecursive(schema.type === 'object' ? {
|
|
196
|
-
|
|
240
|
+
const xmlResult = getExampleValuesFromSchemaRecursive(schema.type === 'object' ? {
|
|
241
|
+
properties: {
|
|
242
|
+
_root: schema
|
|
243
|
+
}
|
|
244
|
+
} : schema, config);
|
|
245
|
+
return xmlResult.map(example => example[0]);
|
|
197
246
|
}
|
|
247
|
+
|
|
198
248
|
return getExampleValuesFromSchemaRecursive(schema, config);
|
|
199
|
-
}
|
|
249
|
+
} // TODO: Support getting the `summary` from the examples object or the `title` from the schema object
|
|
200
250
|
|
|
201
|
-
// TODO: Support getting the `summary` from the examples object or the `title` from the schema object
|
|
202
251
|
function getExampleValuesFromSchemaRecursive(schema, config = {}) {
|
|
203
252
|
if (!schema) {
|
|
204
253
|
return [];
|
|
205
|
-
}
|
|
254
|
+
} // XML Support
|
|
255
|
+
|
|
206
256
|
|
|
207
|
-
// XML Support
|
|
208
257
|
const xmlAttributes = {};
|
|
209
258
|
const xmlTagProperties = [];
|
|
210
|
-
const {
|
|
259
|
+
const {
|
|
260
|
+
prefix,
|
|
261
|
+
namespace
|
|
262
|
+
} = schema.xml || {};
|
|
263
|
+
|
|
211
264
|
if (namespace) {
|
|
212
265
|
xmlAttributes[prefix ? `xmlns:${prefix}` : 'xmlns'] = namespace;
|
|
213
266
|
}
|
|
267
|
+
|
|
214
268
|
const nodeName = schema.items && schema.items.xml && schema.items.xml.name || schema.xml && schema.xml.name || config.propertyName || 'root';
|
|
215
269
|
const overridePropertyName = prefix ? `${prefix}:${nodeName}` : nodeName;
|
|
216
270
|
|
|
@@ -220,55 +274,83 @@ function getExampleValuesFromSchemaRecursive(schema, config = {}) {
|
|
|
220
274
|
}
|
|
221
275
|
|
|
222
276
|
if (schema.oneOf) {
|
|
223
|
-
return schema.oneOf.map(
|
|
277
|
+
return schema.oneOf.map(s => getExampleValuesFromSchemaRecursive(s, config)).flat(1);
|
|
224
278
|
}
|
|
225
279
|
|
|
226
280
|
if (schema.anyOf) {
|
|
227
|
-
return schema.anyOf.map(
|
|
281
|
+
return schema.anyOf.map(s => getExampleValuesFromSchemaRecursive(s, config)).flat(1);
|
|
228
282
|
}
|
|
229
283
|
|
|
230
284
|
if (schema.type === 'array' || schema.items) {
|
|
231
285
|
if (!config.xml) {
|
|
232
286
|
return [getExampleValuesFromSchemaRecursive(schema.items || {}, config)];
|
|
233
287
|
}
|
|
288
|
+
|
|
234
289
|
if (!schema.xml || !schema.xml.wrapped) {
|
|
235
290
|
const arrayExamples = getExampleValuesFromSchemaRecursive(schema.items || {}, config);
|
|
236
|
-
xmlTagProperties.push({
|
|
291
|
+
xmlTagProperties.push({
|
|
292
|
+
[overridePropertyName]: arrayExamples[0]
|
|
293
|
+
}, {
|
|
294
|
+
_attr: xmlAttributes
|
|
295
|
+
});
|
|
237
296
|
return [xmlTagProperties];
|
|
238
297
|
}
|
|
239
298
|
|
|
240
|
-
const arrayExamples = getExampleValuesFromSchemaRecursive(schema.items || {}, { ...config,
|
|
241
|
-
|
|
299
|
+
const arrayExamples = getExampleValuesFromSchemaRecursive(schema.items || {}, { ...config,
|
|
300
|
+
propertyName: overridePropertyName
|
|
301
|
+
});
|
|
302
|
+
xmlTagProperties.push({
|
|
303
|
+
[overridePropertyName]: arrayExamples[0]
|
|
304
|
+
}, {
|
|
305
|
+
_attr: xmlAttributes
|
|
306
|
+
});
|
|
242
307
|
return [xmlTagProperties];
|
|
243
308
|
}
|
|
244
309
|
|
|
245
310
|
if (schema.type === 'object' || schema.properties) {
|
|
246
311
|
let objectExamples = [{}];
|
|
247
|
-
|
|
248
|
-
Object.keys(schema.properties || {}).forEach((propertyName) => {
|
|
312
|
+
Object.keys(schema.properties || {}).forEach(propertyName => {
|
|
249
313
|
const innerSchema = schema.properties[propertyName];
|
|
250
|
-
if (innerSchema.deprecated) { return; }
|
|
251
|
-
if (innerSchema.readOnly && !config.includeReadOnly) { return; }
|
|
252
|
-
if (innerSchema.writeOnly && !config.includeWriteOnly) { return; }
|
|
253
314
|
|
|
254
|
-
|
|
315
|
+
if (innerSchema.deprecated) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (innerSchema.readOnly && !config.includeReadOnly) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (innerSchema.writeOnly && !config.includeWriteOnly) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const propertyExamples = getExampleValuesFromSchemaRecursive(innerSchema, { ...config,
|
|
328
|
+
propertyName
|
|
329
|
+
});
|
|
255
330
|
objectExamples = duplicateExampleWithNewPropertyValues(objectExamples, propertyName, propertyExamples);
|
|
256
331
|
|
|
257
332
|
if (innerSchema.xml && innerSchema.xml.namespace) {
|
|
258
333
|
xmlAttributes[innerSchema.xml.prefix ? `xmlns:${innerSchema.xml.prefix}` : 'xmlns'] = namespace;
|
|
259
334
|
}
|
|
335
|
+
|
|
260
336
|
const innerNodeName = innerSchema.xml && innerSchema.xml.name || propertyName || config.propertyName;
|
|
261
337
|
const innerOverridePropertyName = prefix ? `${prefix}:${innerNodeName}` : innerNodeName;
|
|
262
338
|
|
|
263
339
|
if (innerSchema.xml && innerSchema.xml.attribute) {
|
|
264
340
|
xmlAttributes[innerOverridePropertyName] = propertyExamples[0];
|
|
265
341
|
} else {
|
|
266
|
-
xmlTagProperties.push({
|
|
342
|
+
xmlTagProperties.push({
|
|
343
|
+
[innerOverridePropertyName]: propertyExamples[0]
|
|
344
|
+
});
|
|
267
345
|
}
|
|
268
346
|
});
|
|
347
|
+
|
|
269
348
|
if (Object.keys(xmlAttributes).length) {
|
|
270
|
-
xmlTagProperties.push({
|
|
349
|
+
xmlTagProperties.push({
|
|
350
|
+
_attr: xmlAttributes
|
|
351
|
+
});
|
|
271
352
|
}
|
|
353
|
+
|
|
272
354
|
return config.xml ? [xmlTagProperties] : objectExamples;
|
|
273
355
|
}
|
|
274
356
|
|
|
@@ -280,13 +362,14 @@ function removeTitlesAndDescriptions(obj) {
|
|
|
280
362
|
if (typeof obj !== 'object' || obj === null) {
|
|
281
363
|
return;
|
|
282
364
|
}
|
|
365
|
+
|
|
283
366
|
delete obj['::TITLE'];
|
|
284
367
|
delete obj['::DESCRIPTION'];
|
|
368
|
+
|
|
285
369
|
for (const k in obj) {
|
|
286
370
|
removeTitlesAndDescriptions(obj[k]);
|
|
287
371
|
}
|
|
288
372
|
}
|
|
289
|
-
|
|
290
373
|
/**
|
|
291
374
|
* For changing OpenAPI-Schema to an Object Notation,
|
|
292
375
|
* This Object would further be an input to UI Components to generate an Object-Tree
|
|
@@ -295,51 +378,60 @@ function removeTitlesAndDescriptions(obj) {
|
|
|
295
378
|
* @param {number} level - recursion level
|
|
296
379
|
* @param {string} suffix - used for suffixing property names to avoid duplicate props during object composition
|
|
297
380
|
*/
|
|
381
|
+
|
|
382
|
+
|
|
298
383
|
export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
299
384
|
if (!schema) {
|
|
300
385
|
return undefined;
|
|
301
386
|
}
|
|
387
|
+
|
|
302
388
|
if (schema.allOf) {
|
|
303
389
|
const objWithAllProps = {};
|
|
390
|
+
|
|
304
391
|
if (schema.allOf.length === 1 && !schema.allOf[0].properties && !schema.allOf[0].items) {
|
|
305
392
|
// If allOf has single item and the type is not an object or array, then its a primitive
|
|
306
393
|
const tempSchema = schema.allOf[0];
|
|
307
394
|
return `${getTypeInfo(tempSchema).html}`;
|
|
308
|
-
}
|
|
309
|
-
|
|
395
|
+
} // If allOf is an array of multiple elements, then all the keys makes a single object
|
|
396
|
+
|
|
397
|
+
|
|
310
398
|
schema.allOf.map((v, i) => {
|
|
311
399
|
if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
|
|
312
400
|
const propSuffix = (v.anyOf || v.oneOf) && i > 0 ? i : '';
|
|
313
|
-
const partialObj = schemaInObjectNotation(v, {},
|
|
401
|
+
const partialObj = schemaInObjectNotation(v, {}, level + 1, propSuffix);
|
|
314
402
|
Object.assign(objWithAllProps, partialObj);
|
|
315
403
|
} else if (v.type === 'array' || v.items) {
|
|
316
|
-
const partialObj = schemaInObjectNotation(v, {},
|
|
404
|
+
const partialObj = schemaInObjectNotation(v, {}, level + 1);
|
|
317
405
|
Object.assign(objWithAllProps, partialObj);
|
|
318
406
|
} else if (v.type) {
|
|
319
407
|
const prop = `prop${Object.keys(objWithAllProps).length}`;
|
|
320
408
|
const typeObj = getTypeInfo(v);
|
|
321
409
|
objWithAllProps[prop] = `${typeObj.html}`;
|
|
322
410
|
}
|
|
323
|
-
});
|
|
324
|
-
|
|
411
|
+
}); // eslint-disable-next-line no-param-reassign
|
|
412
|
+
|
|
325
413
|
obj = objWithAllProps;
|
|
326
414
|
} else if (schema.anyOf || schema.oneOf) {
|
|
327
|
-
obj['::description'] = schema.description || '';
|
|
328
|
-
|
|
415
|
+
obj['::description'] = schema.description || ''; // 1. First iterate the regular properties
|
|
416
|
+
|
|
329
417
|
if (schema.type === 'object' || schema.properties) {
|
|
330
418
|
obj['::description'] = schema.description || '';
|
|
331
|
-
obj['::flags'] = {
|
|
332
|
-
|
|
333
|
-
|
|
419
|
+
obj['::flags'] = {
|
|
420
|
+
'🆁': schema.readOnly && '🆁',
|
|
421
|
+
'🆆': schema.writeOnly && '🆆'
|
|
422
|
+
};
|
|
423
|
+
obj['::type'] = 'object'; // obj['::deprecated'] = schema.deprecated || false;
|
|
424
|
+
|
|
334
425
|
for (const key in schema.properties) {
|
|
335
426
|
if (schema.required && schema.required.includes(key)) {
|
|
336
|
-
obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], {},
|
|
427
|
+
obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
|
|
337
428
|
} else {
|
|
338
|
-
obj[key] = schemaInObjectNotation(schema.properties[key], {},
|
|
429
|
+
obj[key] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
|
|
339
430
|
}
|
|
340
431
|
}
|
|
341
|
-
}
|
|
342
|
-
|
|
432
|
+
} // 2. Then show allof/anyof objects
|
|
433
|
+
|
|
434
|
+
|
|
343
435
|
const objWithAnyOfProps = {};
|
|
344
436
|
const xxxOf = schema.anyOf ? 'anyOf' : 'oneOf';
|
|
345
437
|
schema[xxxOf].forEach((v, index) => {
|
|
@@ -358,7 +450,7 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
358
450
|
objWithAnyOfProps['::type'] = 'xxx-of-option';
|
|
359
451
|
}
|
|
360
452
|
});
|
|
361
|
-
obj[
|
|
453
|
+
obj[schema.anyOf ? `::ANY~OF ${suffix}` : `::ONE~OF ${suffix}`] = objWithAnyOfProps;
|
|
362
454
|
obj['::type'] = 'xxx-of';
|
|
363
455
|
} else if (Array.isArray(schema.type)) {
|
|
364
456
|
// 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
|
|
@@ -366,7 +458,7 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
366
458
|
const subSchema = JSON.parse(JSON.stringify(schema));
|
|
367
459
|
const primitiveType = [];
|
|
368
460
|
const complexTypes = [];
|
|
369
|
-
subSchema.type.forEach(
|
|
461
|
+
subSchema.type.forEach(v => {
|
|
370
462
|
if (v.match(/integer|number|string|null|boolean/g)) {
|
|
371
463
|
primitiveType.push(v);
|
|
372
464
|
} else if (v === 'array' && typeof (subSchema.items && subSchema.items.type) === 'string' && schema.items && subSchema.items.type.match(/integer|number|string|null|boolean/g)) {
|
|
@@ -381,20 +473,22 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
381
473
|
}
|
|
382
474
|
});
|
|
383
475
|
let multiPrimitiveTypes;
|
|
476
|
+
|
|
384
477
|
if (primitiveType.length > 0) {
|
|
385
478
|
subSchema.type = primitiveType.join('┃');
|
|
386
479
|
multiPrimitiveTypes = getTypeInfo(subSchema);
|
|
480
|
+
|
|
387
481
|
if (complexTypes.length === 0) {
|
|
388
482
|
return `${multiPrimitiveTypes && multiPrimitiveTypes.html || ''}`;
|
|
389
483
|
}
|
|
390
484
|
}
|
|
485
|
+
|
|
391
486
|
if (complexTypes.length > 0) {
|
|
392
487
|
obj['::type'] = 'xxx-of';
|
|
393
488
|
const multiTypeOptions = {
|
|
394
|
-
'::type': 'xxx-of-option'
|
|
395
|
-
};
|
|
489
|
+
'::type': 'xxx-of-option'
|
|
490
|
+
}; // Generate ONE-OF options for complexTypes
|
|
396
491
|
|
|
397
|
-
// Generate ONE-OF options for complexTypes
|
|
398
492
|
complexTypes.forEach((v, i) => {
|
|
399
493
|
if (v === 'null') {
|
|
400
494
|
multiTypeOptions[`::OPTION~${i + 1}`] = 'NULL~|~~|~~|~~|~~|~~|~~|~~|~';
|
|
@@ -407,25 +501,36 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
407
501
|
const objTypeOption = {
|
|
408
502
|
'::title': schema.title || '',
|
|
409
503
|
'::description': schema.description || '',
|
|
410
|
-
'::flags': {
|
|
504
|
+
'::flags': {
|
|
505
|
+
'🆁': schema.readOnly && '🆁',
|
|
506
|
+
'🆆': schema.writeOnly && '🆆'
|
|
507
|
+
},
|
|
411
508
|
'::type': 'object',
|
|
412
509
|
'::deprecated': schema.deprecated || false
|
|
413
510
|
};
|
|
511
|
+
|
|
414
512
|
for (const key in schema.properties) {
|
|
415
513
|
if (schema.required && schema.required.includes(key)) {
|
|
416
|
-
objTypeOption[`${key}*`] = schemaInObjectNotation(schema.properties[key], {},
|
|
514
|
+
objTypeOption[`${key}*`] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
|
|
417
515
|
} else {
|
|
418
|
-
objTypeOption[key] = schemaInObjectNotation(schema.properties[key], {},
|
|
516
|
+
objTypeOption[key] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
|
|
419
517
|
}
|
|
420
518
|
}
|
|
519
|
+
|
|
421
520
|
multiTypeOptions[`::OPTION~${i + 1}`] = objTypeOption;
|
|
422
521
|
} else if (v === 'array') {
|
|
423
522
|
multiTypeOptions[`::OPTION~${i + 1}`] = {
|
|
424
523
|
'::title': schema.title || '',
|
|
425
524
|
'::description': schema.description || '',
|
|
426
|
-
'::flags': {
|
|
525
|
+
'::flags': {
|
|
526
|
+
'🆁': schema.readOnly && '🆁',
|
|
527
|
+
'🆆': schema.writeOnly && '🆆'
|
|
528
|
+
},
|
|
427
529
|
'::type': 'array',
|
|
428
|
-
'::props': schemaInObjectNotation(Object.assign({
|
|
530
|
+
'::props': schemaInObjectNotation(Object.assign({
|
|
531
|
+
readOnly: schema.readOnly,
|
|
532
|
+
writeOnly: schema.writeOnly
|
|
533
|
+
}, schema.items), {}, level + 1)
|
|
429
534
|
};
|
|
430
535
|
}
|
|
431
536
|
});
|
|
@@ -435,58 +540,72 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
435
540
|
} else if (schema.type === 'object' || schema.properties) {
|
|
436
541
|
obj['::title'] = schema.title || '';
|
|
437
542
|
obj['::description'] = schema.description || '';
|
|
438
|
-
obj['::flags'] = {
|
|
543
|
+
obj['::flags'] = {
|
|
544
|
+
'🆁': schema.readOnly && '🆁',
|
|
545
|
+
'🆆': schema.writeOnly && '🆆'
|
|
546
|
+
};
|
|
439
547
|
obj['::type'] = 'object';
|
|
440
548
|
obj['::deprecated'] = schema.deprecated || false;
|
|
549
|
+
|
|
441
550
|
for (const key in schema.properties) {
|
|
442
551
|
if (schema.required && schema.required.includes(key)) {
|
|
443
|
-
obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], {},
|
|
552
|
+
obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
|
|
444
553
|
} else {
|
|
445
|
-
obj[key] = schemaInObjectNotation(schema.properties[key], {},
|
|
554
|
+
obj[key] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
|
|
446
555
|
}
|
|
447
556
|
}
|
|
557
|
+
|
|
448
558
|
if (schema.additionalProperties) {
|
|
449
559
|
obj['<any-key>'] = schemaInObjectNotation(schema.additionalProperties, {});
|
|
450
560
|
}
|
|
451
|
-
} else if (schema.type === 'array' || schema.items) {
|
|
561
|
+
} else if (schema.type === 'array' || schema.items) {
|
|
562
|
+
// If Array
|
|
452
563
|
obj['::title'] = schema.title || '';
|
|
453
|
-
obj['::description'] = schema.description
|
|
454
|
-
|
|
455
|
-
:
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
obj['::flags'] = { '🆁': schema.readOnly && '🆁', '🆆': schema.writeOnly && '🆆' };
|
|
564
|
+
obj['::description'] = schema.description ? schema.description : schema.items && schema.items.description ? `array<${schema.items.description}>` : '';
|
|
565
|
+
obj['::flags'] = {
|
|
566
|
+
'🆁': schema.readOnly && '🆁',
|
|
567
|
+
'🆆': schema.writeOnly && '🆆'
|
|
568
|
+
};
|
|
459
569
|
obj['::type'] = 'array';
|
|
460
570
|
obj['::deprecated'] = schema.deprecated || false;
|
|
461
|
-
obj['::props'] = schemaInObjectNotation(Object.assign({
|
|
571
|
+
obj['::props'] = schemaInObjectNotation(Object.assign({
|
|
572
|
+
deprecated: schema.deprecated,
|
|
573
|
+
readOnly: schema.readOnly,
|
|
574
|
+
writeOnly: schema.writeOnly
|
|
575
|
+
}, schema.items), {}, level + 1);
|
|
462
576
|
} else {
|
|
463
577
|
const typeObj = getTypeInfo(schema);
|
|
578
|
+
|
|
464
579
|
if (typeObj && typeObj.html) {
|
|
465
580
|
return `${typeObj.html}`;
|
|
466
581
|
}
|
|
582
|
+
|
|
467
583
|
return '';
|
|
468
584
|
}
|
|
585
|
+
|
|
469
586
|
return obj;
|
|
470
587
|
}
|
|
471
|
-
|
|
472
588
|
/* Create Example object */
|
|
589
|
+
|
|
473
590
|
export function generateExample(examples, example, schema, rawMimeType, includeReadOnly = true, includeWriteOnly = true, outputType, skipExampleStrings = false) {
|
|
474
591
|
const mimeType = rawMimeType || 'application/json';
|
|
475
|
-
const finalExamples = [];
|
|
476
|
-
|
|
592
|
+
const finalExamples = []; // First check if examples is provided
|
|
593
|
+
|
|
477
594
|
if (examples) {
|
|
478
595
|
for (const eg in examples) {
|
|
479
596
|
let egContent = '';
|
|
480
597
|
let egFormat = 'json';
|
|
598
|
+
|
|
481
599
|
if (mimeType.toLowerCase().includes('json')) {
|
|
482
600
|
if (outputType === 'text') {
|
|
483
601
|
egContent = typeof examples[eg].value === 'string' ? examples[eg].value : JSON.stringify(examples[eg].value, undefined, 2);
|
|
484
602
|
egFormat = 'text';
|
|
485
603
|
} else {
|
|
486
604
|
egContent = examples[eg].value;
|
|
605
|
+
|
|
487
606
|
if (typeof examples[eg].value === 'string') {
|
|
488
607
|
try {
|
|
489
|
-
const fixedJsonString = examples[eg].value.replace(
|
|
608
|
+
const fixedJsonString = examples[eg].value.replace(/([\w]+)(:)/g, '"$1"$2').replace(/'/g, '"');
|
|
490
609
|
egContent = JSON.parse(fixedJsonString);
|
|
491
610
|
egFormat = 'json';
|
|
492
611
|
} catch (err) {
|
|
@@ -506,12 +625,13 @@ export function generateExample(examples, example, schema, rawMimeType, includeR
|
|
|
506
625
|
exampleDescription: examples[eg].description || '',
|
|
507
626
|
exampleType: mimeType,
|
|
508
627
|
exampleValue: egContent,
|
|
509
|
-
exampleFormat: egFormat
|
|
628
|
+
exampleFormat: egFormat
|
|
510
629
|
});
|
|
511
630
|
}
|
|
512
631
|
} else if (example) {
|
|
513
632
|
let egContent = '';
|
|
514
633
|
let egFormat = 'json';
|
|
634
|
+
|
|
515
635
|
if (mimeType.toLowerCase().includes('json')) {
|
|
516
636
|
if (outputType === 'text') {
|
|
517
637
|
egContent = typeof example === 'string' ? example : JSON.stringify(example, undefined, 2);
|
|
@@ -532,29 +652,31 @@ export function generateExample(examples, example, schema, rawMimeType, includeR
|
|
|
532
652
|
egContent = example;
|
|
533
653
|
egFormat = 'text';
|
|
534
654
|
}
|
|
655
|
+
|
|
535
656
|
finalExamples.push({
|
|
536
657
|
exampleId: 'Example',
|
|
537
658
|
exampleSummary: '',
|
|
538
659
|
exampleDescription: '',
|
|
539
660
|
exampleType: mimeType,
|
|
540
661
|
exampleValue: egContent,
|
|
541
|
-
exampleFormat: egFormat
|
|
662
|
+
exampleFormat: egFormat
|
|
542
663
|
});
|
|
543
|
-
}
|
|
664
|
+
} // If schema-level examples are not provided then generate one based on the schema field types
|
|
665
|
+
|
|
544
666
|
|
|
545
|
-
// If schema-level examples are not provided then generate one based on the schema field types
|
|
546
667
|
if (finalExamples.length) {
|
|
547
668
|
return finalExamples;
|
|
548
669
|
}
|
|
549
670
|
|
|
550
|
-
if (schema && schema.example) {
|
|
671
|
+
if (schema && schema.example) {
|
|
672
|
+
// Note: schema.examples (plurals) is not allowed as per spec
|
|
551
673
|
return [{
|
|
552
674
|
exampleId: 'Example',
|
|
553
675
|
exampleSummary: '',
|
|
554
676
|
exampleDescription: '',
|
|
555
677
|
exampleType: mimeType,
|
|
556
678
|
exampleValue: schema.example,
|
|
557
|
-
exampleFormat:
|
|
679
|
+
exampleFormat: mimeType.toLowerCase().includes('json') && typeof schema.example === 'object' ? 'json' : 'text'
|
|
558
680
|
}];
|
|
559
681
|
}
|
|
560
682
|
|
|
@@ -562,19 +684,18 @@ export function generateExample(examples, example, schema, rawMimeType, includeR
|
|
|
562
684
|
includeReadOnly,
|
|
563
685
|
includeWriteOnly,
|
|
564
686
|
skipExampleStrings,
|
|
565
|
-
xml: mimeType.toLowerCase().includes('xml')
|
|
687
|
+
xml: mimeType.toLowerCase().includes('xml')
|
|
566
688
|
};
|
|
567
|
-
|
|
568
689
|
const samples = getExampleValuesFromSchema(schema, config);
|
|
569
690
|
|
|
570
|
-
if (!samples ||
|
|
691
|
+
if (!samples || !mimeType.toLowerCase().includes('json') && !mimeType.toLowerCase().includes('text') && !mimeType.toLowerCase().includes('*/*') && !mimeType.toLowerCase().includes('xml')) {
|
|
571
692
|
return [{
|
|
572
693
|
exampleId: 'Example',
|
|
573
694
|
exampleSummary: '',
|
|
574
695
|
exampleDescription: '',
|
|
575
696
|
exampleType: mimeType,
|
|
576
697
|
exampleValue: '',
|
|
577
|
-
exampleFormat: 'text'
|
|
698
|
+
exampleFormat: 'text'
|
|
578
699
|
}];
|
|
579
700
|
}
|
|
580
701
|
|
|
@@ -582,10 +703,13 @@ export function generateExample(examples, example, schema, rawMimeType, includeR
|
|
|
582
703
|
const summary = sample['::TITLE'] || `Example ${sampleCounter + 1}`;
|
|
583
704
|
const description = sample['::DESCRIPTION'] || '';
|
|
584
705
|
removeTitlesAndDescriptions(sample);
|
|
585
|
-
|
|
586
706
|
let exampleValue = '';
|
|
707
|
+
|
|
587
708
|
if (mimeType.toLowerCase().includes('xml')) {
|
|
588
|
-
exampleValue = xmlFormatter(sample, {
|
|
709
|
+
exampleValue = xmlFormatter(sample, {
|
|
710
|
+
declaration: true,
|
|
711
|
+
indent: ' '
|
|
712
|
+
});
|
|
589
713
|
} else {
|
|
590
714
|
exampleValue = outputType === 'text' ? JSON.stringify(sample, null, 8) : sample;
|
|
591
715
|
}
|
|
@@ -596,7 +720,7 @@ export function generateExample(examples, example, schema, rawMimeType, includeR
|
|
|
596
720
|
exampleDescription: description,
|
|
597
721
|
exampleType: mimeType,
|
|
598
722
|
exampleFormat: mimeType.toLowerCase().includes('xml') ? 'text' : outputType,
|
|
599
|
-
exampleValue
|
|
723
|
+
exampleValue
|
|
600
724
|
};
|
|
601
|
-
}).filter(
|
|
602
|
-
}
|
|
725
|
+
}).filter(s => s);
|
|
726
|
+
}
|