MCPcopy
hub / github.com/rapi-doc/RapiDoc / ProcessSpec

Function ProcessSpec

src/utils/spec-parser.js:6–173  ·  view source on GitHub ↗
(
  specUrl,
  generateMissingTags = false,
  sortTags = false,
  sortSchemas = false,
  sortEndpointsBy = '',
  attrApiKey = '',
  attrApiKeyLocation = '',
  attrApiKeyValue = '',
  serverUrl = '',
  matchPaths = '',
  matchType = '',
  removeEndpointsWithBadgeLabelAs = '',
)

Source from the content-addressed store, hash-verified

4import { invalidCharsRegEx, rapidocApiKey, sleep } from '~/utils/common-utils';
5
6export 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) {
20 let jsonParsedSpec;
21
22 try {
23 this.requestUpdate(); // important to show the initial loader
24 let specMeta;
25 if (typeof specUrl === 'string') {
26 specMeta = await OpenApiParser.resolve({ url: specUrl, allowMetaPatches: false }); // Swagger(specUrl);
27 } else {
28 specMeta = await OpenApiParser.resolve({ spec: specUrl, allowMetaPatches: false }); // Swagger({ spec: specUrl });
29 }
30 await sleep(0); // important to show the initial loader (allows for rendering updates)
31
32 // If JSON Schema Viewer
33 if (specMeta.resolvedSpec?.jsonSchemaViewer && specMeta.resolvedSpec?.schemaAndExamples) {
34 this.dispatchEvent(new CustomEvent('before-render', { detail: { spec: specMeta.resolvedSpec } }));
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] }));
36 const parsedSpec = {
37 specLoadError: false,
38 isSpecLoading: false,
39 info: specMeta.resolvedSpec.info,
40 schemaAndExamples,
41 };
42 return parsedSpec;
43 }
44
45 // If RapiDoc or RapiDocMini
46 if (specMeta.spec && (specMeta.spec.components || specMeta.spec.info || specMeta.spec.servers || specMeta.spec.tags || specMeta.spec.paths)) {
47 jsonParsedSpec = filterPaths(specMeta.spec, matchPaths, matchType, removeEndpointsWithBadgeLabelAs);
48 this.dispatchEvent(new CustomEvent('before-render', { detail: { spec: jsonParsedSpec } }));
49 } else {
50 console.info('RapiDoc: %c There was an issue while parsing the spec %o ', 'color:orangered', specMeta); // eslint-disable-line no-console
51 return {
52 specLoadError: true,
53 isSpecLoading: false,
54 info: {
55 title: 'Error loading the spec',
56 description: specMeta.response?.url ? `${specMeta.response?.url} ┃ ${specMeta.response?.status} ${specMeta.response?.statusText}` : 'Unable to load the Spec',
57 version: ' ',
58 },
59 tags: [],
60 };
61 }
62 } catch (err) {
63 console.info('RapiDoc: %c There was an issue while parsing the spec %o ', 'color:orangered', err); // eslint-disable-line no-console

Callers

nothing calls this directly

Calls 13

sleepFunction · 0.90
filterPathsFunction · 0.70
groupByTagsFunction · 0.70
getComponentsFunction · 0.70
getHeadersFromMarkdownFunction · 0.70
requestUpdateMethod · 0.45
resolveMethod · 0.45
mapMethod · 0.45
infoMethod · 0.45
forEachMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…