rapidoc 9.3.4 → 9.3.6
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/README.md +2 -7
- package/dist/index.html +1 -1
- package/dist/index.html.gz +0 -0
- package/dist/rapidoc-min.js +529 -525
- package/dist/rapidoc-min.js.LICENSE.txt +8 -4
- package/dist/rapidoc-min.js.LICENSE.txt.gz +0 -0
- package/dist/rapidoc-min.js.gz +0 -0
- package/dist/rapidoc-min.js.map +1 -1
- package/dist/rapidoc-min.js.map.gz +0 -0
- package/dist/rapidoc.js +1900 -8151
- package/dist/report.html +5 -5
- package/index.html +3 -2
- package/package.json +23 -22
- package/src/components/api-request.js +49 -11
- package/src/components/schema-table.js +11 -10
- package/src/components/schema-tree.js +7 -6
- package/src/json-schema-viewer.js +1 -0
- package/src/rapidoc.js +10 -5
- package/src/templates/advance-search-template.js +3 -3
- package/src/templates/endpoint-template.js +1 -1
- package/src/templates/expanded-endpoint-template.js +1 -1
- package/src/templates/focused-endpoint-template.js +1 -1
- package/src/templates/navbar-template.js +2 -2
- package/src/templates/security-scheme-template.js +5 -4
- package/src/utils/common-utils.js +1 -1
- package/src/utils/schema-utils.js +32 -5
- package/src/utils/spec-parser.js +8 -3
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import RandExp from 'randexp';
|
|
2
|
+
|
|
3
|
+
// Make RandExp determinist
|
|
4
|
+
RandExp.prototype.randInt = (from) => from;
|
|
5
|
+
|
|
1
6
|
// Takes a value as input and provides a printable string to replresent null values, spaces, blankstring etc
|
|
2
7
|
export function getPrintableVal(val) {
|
|
3
8
|
if (val === undefined) {
|
|
@@ -15,6 +20,10 @@ export function getPrintableVal(val) {
|
|
|
15
20
|
if (Array.isArray(val)) {
|
|
16
21
|
return val.map((v) => (v === null ? 'null' : v === '' ? '∅' : v.toString().replace(/^ +| +$/g, (m) => '●'.repeat(m.length)) || '')).join(', ');
|
|
17
22
|
}
|
|
23
|
+
if (typeof val === 'object') {
|
|
24
|
+
const keys = Object.keys(val);
|
|
25
|
+
return `{ ${keys[0]}:${val[keys[0]]}${keys.length > 1 ? ',' : ''} ... }`;
|
|
26
|
+
}
|
|
18
27
|
return val.toString().replace(/^ +| +$/g, (m) => '●'.repeat(m.length)) || '';
|
|
19
28
|
}
|
|
20
29
|
|
|
@@ -154,7 +163,7 @@ export function normalizeExamples(examples, dataType = 'string') {
|
|
|
154
163
|
description: v.description || '',
|
|
155
164
|
}));
|
|
156
165
|
const exampleVal = exampleList.length > 0
|
|
157
|
-
? exampleList[0].value
|
|
166
|
+
? exampleList[0].value
|
|
158
167
|
: '';
|
|
159
168
|
return { exampleVal, exampleList };
|
|
160
169
|
}
|
|
@@ -219,7 +228,7 @@ export function getSampleValueByType(schemaObj) {
|
|
|
219
228
|
}
|
|
220
229
|
if (schemaObj.$ref) {
|
|
221
230
|
// Indicates a Circular ref
|
|
222
|
-
return
|
|
231
|
+
return {};
|
|
223
232
|
}
|
|
224
233
|
if (schemaObj.const === false || schemaObj.const === 0 || schemaObj.const === null || schemaObj.const === '') {
|
|
225
234
|
return schemaObj.const;
|
|
@@ -227,9 +236,12 @@ export function getSampleValueByType(schemaObj) {
|
|
|
227
236
|
if (schemaObj.const) {
|
|
228
237
|
return schemaObj.const;
|
|
229
238
|
}
|
|
239
|
+
if (schemaObj.default) {
|
|
240
|
+
return schemaObj.default;
|
|
241
|
+
}
|
|
230
242
|
const typeValue = Array.isArray(schemaObj.type) ? schemaObj.type[0] : schemaObj.type;
|
|
231
243
|
if (!typeValue) {
|
|
232
|
-
return
|
|
244
|
+
return null;
|
|
233
245
|
}
|
|
234
246
|
if (typeValue.match(/^integer|^number/g)) {
|
|
235
247
|
const multipleOf = Number.isNaN(Number(schemaObj.multipleOf)) ? undefined : Number(schemaObj.multipleOf);
|
|
@@ -253,7 +265,13 @@ export function getSampleValueByType(schemaObj) {
|
|
|
253
265
|
if (typeValue.match(/^string/g)) {
|
|
254
266
|
if (schemaObj.enum) { return schemaObj.enum[0]; }
|
|
255
267
|
if (schemaObj.const) { return schemaObj.const; }
|
|
256
|
-
if (schemaObj.pattern) {
|
|
268
|
+
if (schemaObj.pattern) {
|
|
269
|
+
try {
|
|
270
|
+
return new RandExp(schemaObj.pattern).gen();
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return schemaObj.pattern;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
257
275
|
if (schemaObj.format) {
|
|
258
276
|
const u = `${Date.now().toString(16)}${Math.random().toString(16)}0`.repeat(16);
|
|
259
277
|
switch (schemaObj.format.toLowerCase()) {
|
|
@@ -280,6 +298,8 @@ export function getSampleValueByType(schemaObj) {
|
|
|
280
298
|
return '2001:0db8:5b96:0000:0000:426f:8e17:642a';
|
|
281
299
|
case 'uuid':
|
|
282
300
|
return [u.substr(0, 8), u.substr(8, 4), `4000-8${u.substr(13, 3)}`, u.substr(16, 12)].join('-');
|
|
301
|
+
case 'byte':
|
|
302
|
+
return 'ZXhhbXBsZQ=='; // 'example' base64 encoded. See https://spec.openapis.org/oas/v3.0.0#data-types
|
|
283
303
|
default:
|
|
284
304
|
return '';
|
|
285
305
|
}
|
|
@@ -291,7 +311,7 @@ export function getSampleValueByType(schemaObj) {
|
|
|
291
311
|
}
|
|
292
312
|
}
|
|
293
313
|
// If type cannot be determined
|
|
294
|
-
return
|
|
314
|
+
return null;
|
|
295
315
|
}
|
|
296
316
|
|
|
297
317
|
/*
|
|
@@ -584,6 +604,11 @@ export function schemaToSampleObj(schema, config = { }) {
|
|
|
584
604
|
}
|
|
585
605
|
obj = mergePropertyExamples(obj, propertyName, schemaToSampleObj(schema.properties[propertyName], config));
|
|
586
606
|
}
|
|
607
|
+
if (typeof schema.additionalProperties === 'object') {
|
|
608
|
+
const propertyName = schema.additionalProperties['x-additionalPropertiesName'] || 'property';
|
|
609
|
+
obj = mergePropertyExamples(obj, `${propertyName}1`, schemaToSampleObj(schema.additionalProperties, config));
|
|
610
|
+
obj = mergePropertyExamples(obj, `${propertyName}2`, schemaToSampleObj(schema.additionalProperties, config));
|
|
611
|
+
}
|
|
587
612
|
}
|
|
588
613
|
} else if (schema.type === 'array' || schema.items) {
|
|
589
614
|
if (schema.items || schema.example) {
|
|
@@ -790,6 +815,7 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
790
815
|
obj['::type'] = 'object';
|
|
791
816
|
if ((Array.isArray(schema.type) && schema.type.includes('null')) || schema.nullable) {
|
|
792
817
|
obj['::dataTypeLabel'] = 'object or null';
|
|
818
|
+
obj['::nullable'] = true;
|
|
793
819
|
}
|
|
794
820
|
obj['::deprecated'] = schema.deprecated || false;
|
|
795
821
|
obj['::readwrite'] = schema.readOnly ? 'readonly' : schema.writeOnly ? 'writeonly' : '';
|
|
@@ -812,6 +838,7 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
|
|
|
812
838
|
obj['::type'] = 'array';
|
|
813
839
|
if ((Array.isArray(schema.type) && schema.type.includes('null')) || schema.nullable) {
|
|
814
840
|
obj['::dataTypeLabel'] = 'array or null';
|
|
841
|
+
obj['::nullable'] = true;
|
|
815
842
|
}
|
|
816
843
|
obj['::deprecated'] = schema.deprecated || false;
|
|
817
844
|
obj['::readwrite'] = schema.readOnly ? 'readonly' : schema.writeOnly ? 'writeonly' : '';
|
package/src/utils/spec-parser.js
CHANGED
|
@@ -3,7 +3,7 @@ import OpenApiParser from '@apitools/openapi-parser';
|
|
|
3
3
|
import { marked } from 'marked';
|
|
4
4
|
import { invalidCharsRegEx, rapidocApiKey, sleep } from '~/utils/common-utils';
|
|
5
5
|
|
|
6
|
-
export default async function ProcessSpec(specUrl, generateMissingTags = false, sortTags = false, sortEndpointsBy = '', attrApiKey = '', attrApiKeyLocation = '', attrApiKeyValue = '', serverUrl = '') {
|
|
6
|
+
export default async function ProcessSpec(specUrl, generateMissingTags = false, sortTags = false, sortSchemas = false, sortEndpointsBy = '', attrApiKey = '', attrApiKeyLocation = '', attrApiKeyValue = '', serverUrl = '') {
|
|
7
7
|
let jsonParsedSpec;
|
|
8
8
|
try {
|
|
9
9
|
this.requestUpdate(); // important to show the initial loader
|
|
@@ -53,7 +53,7 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
|
|
|
53
53
|
const tags = groupByTags(jsonParsedSpec, sortEndpointsBy, generateMissingTags, sortTags);
|
|
54
54
|
|
|
55
55
|
// Components
|
|
56
|
-
const components = getComponents(jsonParsedSpec);
|
|
56
|
+
const components = getComponents(jsonParsedSpec, sortSchemas);
|
|
57
57
|
|
|
58
58
|
// Info Description Headers
|
|
59
59
|
const infoDescriptionHeaders = jsonParsedSpec.info?.description ? getHeadersFromMarkdown(jsonParsedSpec.info.description) : [];
|
|
@@ -162,7 +162,7 @@ function getHeadersFromMarkdown(markdownContent) {
|
|
|
162
162
|
return headers || [];
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
function getComponents(openApiSpec) {
|
|
165
|
+
function getComponents(openApiSpec, sortSchemas = false) {
|
|
166
166
|
if (!openApiSpec.components) {
|
|
167
167
|
return [];
|
|
168
168
|
}
|
|
@@ -184,6 +184,10 @@ function getComponents(openApiSpec) {
|
|
|
184
184
|
|
|
185
185
|
switch (component) {
|
|
186
186
|
case 'schemas':
|
|
187
|
+
if (sortSchemas) {
|
|
188
|
+
subComponents.sort((c1, c2) => c1.name.localeCompare(c2.name));
|
|
189
|
+
}
|
|
190
|
+
|
|
187
191
|
cmpName = 'Schemas';
|
|
188
192
|
cmpDescription = 'Schemas allows the definition of input and output data types. These types can be objects, but also primitives and arrays.';
|
|
189
193
|
break;
|
|
@@ -246,6 +250,7 @@ function groupByTags(openApiSpec, sortEndpointsBy, generateMissingTags = false,
|
|
|
246
250
|
show: true,
|
|
247
251
|
elementId: `tag--${v.name.replace(invalidCharsRegEx, '-')}`,
|
|
248
252
|
name: v.name,
|
|
253
|
+
displayName: v['x-displayName'] || v.name,
|
|
249
254
|
description: v.description || '',
|
|
250
255
|
headers: v.description ? getHeadersFromMarkdown(v.description) : [],
|
|
251
256
|
paths: [],
|