rapidoc 9.3.5 → 9.3.7
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/.eslintrc +9 -1
- package/dist/index.html +1 -1
- package/dist/index.html.gz +0 -0
- package/dist/rapidoc-min.js +393 -379
- package/dist/rapidoc-min.js.LICENSE.txt +1 -8
- 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 +441 -247
- package/dist/report.html +2 -2
- package/index.html +5 -4
- package/package.json +2 -2
- package/src/components/api-request.js +116 -78
- package/src/components/api-response.js +6 -7
- package/src/components/schema-table.js +6 -5
- package/src/components/schema-tree.js +9 -7
- package/src/json-schema-viewer.js +6 -2
- package/src/rapidoc-mini.js +20 -4
- package/src/rapidoc.js +33 -18
- package/src/styles/border-styles.js +2 -2
- package/src/styles/endpoint-styles.js +13 -10
- package/src/styles/flex-styles.js +1 -1
- package/src/styles/font-styles.js +13 -13
- package/src/styles/input-styles.js +2 -2
- package/src/styles/nav-styles.js +1 -1
- package/src/styles/schema-styles.js +12 -9
- package/src/templates/advance-search-template.js +2 -1
- package/src/templates/endpoint-template.js +30 -27
- package/src/templates/expanded-endpoint-template.js +5 -3
- package/src/templates/focused-endpoint-template.js +1 -1
- package/src/templates/json-schema-viewer-template.js +3 -3
- package/src/templates/main-body-template.js +2 -2
- package/src/templates/navbar-template.js +7 -7
- package/src/templates/security-scheme-template.js +9 -7
- package/src/utils/common-utils.js +5 -9
- package/src/utils/schema-utils.js +65 -16
- package/src/utils/spec-parser.js +77 -7
- package/src/utils/theme.js +4 -6
package/src/utils/spec-parser.js
CHANGED
|
@@ -3,8 +3,22 @@ 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(
|
|
6
|
+
export default async function ProcessSpec(
|
|
7
|
+
specUrl,
|
|
8
|
+
generateMissingTags = false,
|
|
9
|
+
sortTags = false,
|
|
10
|
+
sortSchemas = false,
|
|
11
|
+
sortEndpointsBy = '',
|
|
12
|
+
attrApiKey = '',
|
|
13
|
+
attrApiKeyLocation = '',
|
|
14
|
+
attrApiKeyValue = '',
|
|
15
|
+
serverUrl = '',
|
|
16
|
+
matchPaths = '',
|
|
17
|
+
matchType = '',
|
|
18
|
+
removeEndpointsWithBadgeLabelAs = '',
|
|
19
|
+
) {
|
|
7
20
|
let jsonParsedSpec;
|
|
21
|
+
|
|
8
22
|
try {
|
|
9
23
|
this.requestUpdate(); // important to show the initial loader
|
|
10
24
|
let specMeta;
|
|
@@ -15,7 +29,7 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
|
|
|
15
29
|
}
|
|
16
30
|
await sleep(0); // important to show the initial loader (allows for rendering updates)
|
|
17
31
|
|
|
18
|
-
// If
|
|
32
|
+
// If JSON Schema Viewer
|
|
19
33
|
if (specMeta.resolvedSpec?.jsonSchemaViewer && specMeta.resolvedSpec?.schemaAndExamples) {
|
|
20
34
|
this.dispatchEvent(new CustomEvent('before-render', { detail: { spec: specMeta.resolvedSpec } }));
|
|
21
35
|
const schemaAndExamples = Object.entries(specMeta.resolvedSpec.schemaAndExamples).map((v) => ({ show: true, expanded: true, selectedExample: null, name: v[0], elementId: v[0].replace(invalidCharsRegEx, '-'), ...v[1] }));
|
|
@@ -27,8 +41,10 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
|
|
|
27
41
|
};
|
|
28
42
|
return parsedSpec;
|
|
29
43
|
}
|
|
44
|
+
|
|
45
|
+
// If RapiDoc or RapiDocMini
|
|
30
46
|
if (specMeta.spec && (specMeta.spec.components || specMeta.spec.info || specMeta.spec.servers || specMeta.spec.tags || specMeta.spec.paths)) {
|
|
31
|
-
jsonParsedSpec = specMeta.spec;
|
|
47
|
+
jsonParsedSpec = filterPaths(specMeta.spec, matchPaths, matchType, removeEndpointsWithBadgeLabelAs);
|
|
32
48
|
this.dispatchEvent(new CustomEvent('before-render', { detail: { spec: jsonParsedSpec } }));
|
|
33
49
|
} else {
|
|
34
50
|
console.info('RapiDoc: %c There was an issue while parsing the spec %o ', 'color:orangered', specMeta); // eslint-disable-line no-console
|
|
@@ -112,7 +128,7 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
|
|
|
112
128
|
|
|
113
129
|
// Servers
|
|
114
130
|
let servers = [];
|
|
115
|
-
if (jsonParsedSpec.servers && Array.isArray(jsonParsedSpec.servers)) {
|
|
131
|
+
if (jsonParsedSpec.servers && Array.isArray(jsonParsedSpec.servers) && jsonParsedSpec.servers.length > 0) {
|
|
116
132
|
jsonParsedSpec.servers.forEach((v) => {
|
|
117
133
|
let computedUrl = v.url.trim();
|
|
118
134
|
if (!(computedUrl.startsWith('http') || computedUrl.startsWith('//') || computedUrl.startsWith('{'))) {
|
|
@@ -141,7 +157,7 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
|
|
|
141
157
|
} else {
|
|
142
158
|
jsonParsedSpec.servers = [{ url: 'http://localhost', computedUrl: 'http://localhost' }];
|
|
143
159
|
}
|
|
144
|
-
servers = jsonParsedSpec.servers;
|
|
160
|
+
servers = jsonParsedSpec.servers; // eslint-disable-line prefer-destructuring
|
|
145
161
|
const parsedSpec = {
|
|
146
162
|
specLoadError: false,
|
|
147
163
|
isSpecLoading: false,
|
|
@@ -156,6 +172,60 @@ export default async function ProcessSpec(specUrl, generateMissingTags = false,
|
|
|
156
172
|
return parsedSpec;
|
|
157
173
|
}
|
|
158
174
|
|
|
175
|
+
function filterPaths(openApiObject, matchPaths = '', matchType = '', removeEndpointsWithBadgeLabelAs = '') {
|
|
176
|
+
const filteredPaths = {};
|
|
177
|
+
|
|
178
|
+
// Convert the removePathsWithBadgeLabeledAs to an array if provided
|
|
179
|
+
const labelsToRemove = removeEndpointsWithBadgeLabelAs.split(',').map((label) => label.trim().toLowerCase()).filter(Boolean);
|
|
180
|
+
|
|
181
|
+
// Helper function to check if a path should be included based on matchPaths
|
|
182
|
+
function pathMatches(pathsKey, httpMethod) {
|
|
183
|
+
if (!matchPaths) {
|
|
184
|
+
return true; // If no matchPaths provided, include everything
|
|
185
|
+
}
|
|
186
|
+
const fullPath = `${httpMethod} ${pathsKey}`.toLowerCase(); // Construct "method path" string
|
|
187
|
+
if (matchType === 'regex') {
|
|
188
|
+
const regex = new RegExp(matchPaths, 'i');
|
|
189
|
+
return regex.test(matchPaths.toLowerCase());
|
|
190
|
+
}
|
|
191
|
+
return fullPath.includes(matchPaths.toLowerCase());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Helper function to check if the badges contain any label that needs to be removed
|
|
195
|
+
function containsLabelToRemove(badges) {
|
|
196
|
+
return badges.some((badge) => labelsToRemove.includes(badge?.label.toLowerCase()));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Loop through the paths in the openApiObject
|
|
200
|
+
Object.entries(openApiObject.paths).forEach(([pathsKey, methods]) => {
|
|
201
|
+
const filteredMethods = {};
|
|
202
|
+
|
|
203
|
+
Object.entries(methods).forEach(([httpMethod, methodDetails]) => {
|
|
204
|
+
const badges = methodDetails['x-badges'];
|
|
205
|
+
|
|
206
|
+
// Filter by matchPaths
|
|
207
|
+
if (pathMatches(pathsKey, httpMethod)) {
|
|
208
|
+
if (badges && Array.isArray(badges)) {
|
|
209
|
+
// Filter out based on removePathsWithBadgeLabeledAs
|
|
210
|
+
if (!containsLabelToRemove(badges)) {
|
|
211
|
+
filteredMethods[httpMethod] = methodDetails;
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
// No badges present, include the method
|
|
215
|
+
filteredMethods[httpMethod] = methodDetails;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (Object.keys(filteredMethods).length > 0) {
|
|
221
|
+
filteredPaths[pathsKey] = filteredMethods;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
openApiObject.paths = filteredPaths;
|
|
226
|
+
return openApiObject;
|
|
227
|
+
}
|
|
228
|
+
|
|
159
229
|
function getHeadersFromMarkdown(markdownContent) {
|
|
160
230
|
const tokens = marked.lexer(markdownContent);
|
|
161
231
|
const headers = tokens.filter((v) => v.type === 'heading' && v.depth <= 2);
|
|
@@ -245,7 +315,7 @@ function getComponents(openApiSpec, sortSchemas = false) {
|
|
|
245
315
|
|
|
246
316
|
function groupByTags(openApiSpec, sortEndpointsBy, generateMissingTags = false, sortTags = false) {
|
|
247
317
|
const supportedMethods = ['get', 'put', 'post', 'delete', 'patch', 'head', 'options']; // this is also used for ordering endpoints by methods
|
|
248
|
-
const tags = openApiSpec.tags && Array.isArray(openApiSpec.tags)
|
|
318
|
+
const tags = openApiSpec.tags && Array.isArray(openApiSpec.tags) && openApiSpec.tags.length > 0
|
|
249
319
|
? openApiSpec.tags.map((v) => ({
|
|
250
320
|
show: true,
|
|
251
321
|
elementId: `tag--${v.name.replace(invalidCharsRegEx, '-')}`,
|
|
@@ -286,7 +356,7 @@ function groupByTags(openApiSpec, sortEndpointsBy, generateMissingTags = false,
|
|
|
286
356
|
pathTags.push(pathOrHookNameKey);
|
|
287
357
|
} else {
|
|
288
358
|
// firstWordEndIndex -= 1;
|
|
289
|
-
pathTags.push(pathOrHookNameKey.
|
|
359
|
+
pathTags.push(pathOrHookNameKey.substring(0, firstWordEndIndex));
|
|
290
360
|
}
|
|
291
361
|
} else {
|
|
292
362
|
pathTags.push('General ⦂');
|
package/src/utils/theme.js
CHANGED
|
@@ -21,8 +21,8 @@ export default function setTheme(baseTheme, theme = {}) {
|
|
|
21
21
|
const fg3 = theme.fg3 ? theme.fg3 : ColorUtils.color.brightness(fg1, -20); // or #aaa
|
|
22
22
|
const lightFg = theme.fg3 ? theme.fg3 : ColorUtils.color.brightness(fg1, -65); // or #777
|
|
23
23
|
const inlineCodeFg = theme.inlineCodeFg ? theme.inlineCodeFg : '#aaa';
|
|
24
|
-
const selectionBg =
|
|
25
|
-
const selectionFg =
|
|
24
|
+
const selectionBg = fg2;
|
|
25
|
+
const selectionFg = bg2;
|
|
26
26
|
|
|
27
27
|
const headerColor = theme.headerColor ? theme.headerColor : ColorUtils.color.brightness(bg1, 10);
|
|
28
28
|
|
|
@@ -107,10 +107,8 @@ export default function setTheme(baseTheme, theme = {}) {
|
|
|
107
107
|
const fg3 = theme.fg3 ? theme.fg3 : ColorUtils.color.brightness(fg1, 30); // or #666
|
|
108
108
|
const lightFg = theme.fg3 ? theme.fg3 : ColorUtils.color.brightness(fg1, 70); // or #999
|
|
109
109
|
const inlineCodeFg = theme.inlineCodeFg ? theme.inlineCodeFg : 'brown';
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
const selectionFg = '#eee';
|
|
113
|
-
|
|
110
|
+
const selectionBg = fg2;
|
|
111
|
+
const selectionFg = bg2;
|
|
114
112
|
const headerColor = theme.headerColor ? theme.headerColor : ColorUtils.color.brightness(bg1, -180);
|
|
115
113
|
|
|
116
114
|
/*
|