rapidoc 11.0.1 → 12.0.0

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.
Files changed (80) hide show
  1. package/README.md +46 -31
  2. package/dist/rapidoc-min.js +1424 -213
  3. package/dist/rapidoc-static-min.js +13542 -0
  4. package/package.json +47 -35
  5. package/src/components/api-request.ts +869 -0
  6. package/src/components/api-response.ts +509 -0
  7. package/src/components/json-tree.ts +171 -0
  8. package/src/components/schema-base-element.ts +315 -0
  9. package/src/components/schema-table.ts +430 -0
  10. package/src/components/schema-tree.ts +386 -0
  11. package/src/components/tag-input.ts +184 -0
  12. package/src/index.js +6 -0
  13. package/src/oauth-receiver.ts +29 -0
  14. package/src/rapidoc-mini.ts +582 -0
  15. package/src/rapidoc.ts +1808 -0
  16. package/src/static/index.d.ts +149 -0
  17. package/src/static/index.js +62 -0
  18. package/src/static/navigation.js +497 -0
  19. package/src/static/render.js +490 -0
  20. package/src/static/serializer.js +216 -0
  21. package/src/styles/auth-styles.js +318 -0
  22. package/src/styles/border-styles.js +24 -0
  23. package/src/styles/css-bundle.js +129 -0
  24. package/src/styles/custom-styles.js +8 -0
  25. package/src/styles/dialog-box-styles.js +102 -0
  26. package/src/styles/endpoint-styles.js +559 -0
  27. package/src/styles/flex-styles.js +16 -0
  28. package/src/styles/font-styles.js +432 -0
  29. package/src/styles/info-styles.js +36 -0
  30. package/src/styles/input-styles.js +555 -0
  31. package/src/styles/layout-styles.js +396 -0
  32. package/src/styles/microlighter-styles.js +99 -0
  33. package/src/styles/nav-styles.js +609 -0
  34. package/src/styles/param-list-styles.js +261 -0
  35. package/src/styles/schema-styles.js +288 -0
  36. package/src/styles/tab-styles.js +106 -0
  37. package/src/styles/theme-tokens.js +582 -0
  38. package/src/templates/advanced-search-dialog-template.js +94 -0
  39. package/src/templates/api-response-template.js +219 -0
  40. package/src/templates/callback-template.js +86 -0
  41. package/src/templates/code-samples-template.js +52 -0
  42. package/src/templates/components-template.js +86 -0
  43. package/src/templates/downloads-template.js +85 -0
  44. package/src/templates/endpoint-template.js +386 -0
  45. package/src/templates/expanded-endpoint-template.js +266 -0
  46. package/src/templates/focused-endpoint-template.js +145 -0
  47. package/src/templates/header-template.js +92 -0
  48. package/src/templates/logo-template.js +21 -0
  49. package/src/templates/main-body-template.js +102 -0
  50. package/src/templates/navbar-template.js +489 -0
  51. package/src/templates/overview-template.js +104 -0
  52. package/src/templates/request-body-template.js +651 -0
  53. package/src/templates/request-params-template.js +474 -0
  54. package/src/templates/security-scheme-template.js +1263 -0
  55. package/src/templates/server-template.js +152 -0
  56. package/src/utils/auto-color-scheme.js +99 -0
  57. package/src/utils/bind-navbar.js +175 -0
  58. package/src/utils/color-utils.js +59 -0
  59. package/src/utils/common-utils.js +191 -0
  60. package/src/utils/curl-utils.js +123 -0
  61. package/src/utils/highlighter.js +416 -0
  62. package/src/utils/markdown-utils.js +110 -0
  63. package/src/utils/mcp/common.js +467 -0
  64. package/src/utils/mcp/generators/csharp.js +242 -0
  65. package/src/utils/mcp/generators/go.js +298 -0
  66. package/src/utils/mcp/generators/java.js +330 -0
  67. package/src/utils/mcp/generators/python.js +248 -0
  68. package/src/utils/mcp/generators/rust.js +281 -0
  69. package/src/utils/mcp/generators/typescript.js +290 -0
  70. package/src/utils/mcp-generator.js +143 -0
  71. package/src/utils/mock-interceptor.js +508 -0
  72. package/src/utils/oauth-utils.js +87 -0
  73. package/src/utils/request-utils.js +203 -0
  74. package/src/utils/response-utils.js +203 -0
  75. package/src/utils/sanitize.js +57 -0
  76. package/src/utils/schema-utils.js +1927 -0
  77. package/src/utils/slugger.js +189 -0
  78. package/src/utils/spec-parser.js +915 -0
  79. package/src/utils/url-utils.js +211 -0
  80. package/src/utils/xml-utils.js +61 -0
@@ -0,0 +1,582 @@
1
+ import { css, LitElement } from "lit";
2
+ import { customElement, property } from "lit/decorators.js";
3
+ import { scheduleHighlight } from "~/utils/highlighter";
4
+
5
+ // Styles
6
+ import FontStyles from "~/styles/font-styles";
7
+ import InputStyles from "~/styles/input-styles";
8
+ import FlexStyles from "~/styles/flex-styles";
9
+ import AuthStyles from "~/styles/auth-styles";
10
+ import ParamListStyles from "~/styles/param-list-styles";
11
+ import MicrolighterStyles from "~/styles/microlighter-styles";
12
+ import TabStyles from "~/styles/tab-styles";
13
+ import NavStyles from "~/styles/nav-styles";
14
+ import InfoStyles from "~/styles/info-styles";
15
+
16
+ import EndpointStyles from "~/styles/endpoint-styles";
17
+ import ThemeTokens, {
18
+ DEFAULT_THEME,
19
+ applyCustomTheme,
20
+ isValidHexColor,
21
+ normalizeTheme,
22
+ } from "~/styles/theme-tokens";
23
+ import { rapidocApiKey } from "~/utils/common-utils";
24
+ import ProcessSpec from "~/utils/spec-parser";
25
+ import { enableMockServer, disableMockServer, updateMockConfig } from "~/utils/mock-interceptor";
26
+ import mainBodyTemplate from "~/templates/main-body-template";
27
+ import { applyApiKey, onClearAllApiKeys } from "~/templates/security-scheme-template";
28
+ import { setApiServer } from "~/templates/server-template";
29
+ import "~/utils/markdown-utils";
30
+ import { AutoColorSchemeController } from "~/utils/auto-color-scheme";
31
+
32
+ const paramsConverter = {
33
+ fromAttribute: (attr: string | null) => {
34
+ if (!attr) {
35
+ return null;
36
+ }
37
+ const trimmed = attr.trim();
38
+ if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
39
+ try {
40
+ return JSON.parse(trimmed);
41
+ } catch {
42
+ return trimmed;
43
+ }
44
+ }
45
+ return trimmed;
46
+ },
47
+ toAttribute: (prop: any) => {
48
+ if (typeof prop === "object" && prop !== null) {
49
+ return JSON.stringify(prop);
50
+ }
51
+ return prop;
52
+ },
53
+ };
54
+
55
+ @customElement("rapi-doc-mini")
56
+ export default class RapiDocMini extends LitElement {
57
+ // Spec
58
+ @property({ type: String, attribute: "spec-url" }) specUrl = "";
59
+ @property({ type: String, attribute: "sort-endpoints-by" }) sortEndpointsBy = "path";
60
+
61
+ // UI Layouts
62
+ @property({ type: String }) layout = "row";
63
+ @property({ type: String, attribute: "paths-expanded" }) pathsExpanded: any = "false";
64
+ @property({ type: String, attribute: "default-schema-tab" }) defaultSchemaTab = "example";
65
+ @property({ type: String, attribute: "response-area-height" }) responseAreaHeight = "300px";
66
+ @property({ type: String, attribute: "show-summary-when-collapsed" }) showSummaryWhenCollapsed =
67
+ "true";
68
+ @property({ type: String, attribute: "fill-request-fields-with-example" })
69
+ fillRequestFieldsWithExample = "true";
70
+ @property({ type: String, attribute: "persist-auth" }) persistAuth = "false";
71
+
72
+ // Schema Styles
73
+ @property({ type: String, attribute: "schema-style" }) schemaStyle = "tree";
74
+ @property({ type: Number, attribute: "schema-expand-level" }) schemaExpandLevel = 99999;
75
+ @property({ type: String, attribute: "schema-description-expanded" }) schemaDescriptionExpanded =
76
+ "false";
77
+
78
+ // API Server
79
+ @property({ type: String, attribute: "api-key-name" }) apiKeyName = "";
80
+ @property({ type: String, attribute: "api-key-location" }) apiKeyLocation = "header";
81
+ @property({ type: String, attribute: "api-key-value" }) apiKeyValue = "-";
82
+ @property({ type: String, attribute: "default-api-server" }) defaultApiServerUrl = "";
83
+ @property({ type: String, attribute: "server-url" }) serverUrl = "";
84
+ @property({ type: String, attribute: "oauth-receiver" }) oauthReceiver = "oauth-receiver.html";
85
+ @property({ type: Object, attribute: "additional-authorize-params", converter: paramsConverter })
86
+ additionalAuthorizeParams: any;
87
+ @property({ type: Object, attribute: "additional-token-params", converter: paramsConverter })
88
+ additionalTokenParams: any;
89
+
90
+ // Mock Server
91
+ @property({ type: String, attribute: "mock-server" }) mockServer = "false";
92
+ @property({ type: String, attribute: "mock-server-status-code" }) mockServerStatusCode = "200";
93
+ @property({ type: String, attribute: "mock-server-status-strategy" }) mockServerStatusStrategy =
94
+ "example";
95
+ @property({ type: Number, attribute: "mock-server-delay" }) mockServerDelay = 0;
96
+ @property({ type: String, attribute: "mock-server-log" }) mockServerLog = "false";
97
+
98
+ @property({ type: String, attribute: "allow-try" }) allowTry = "true";
99
+ @property({ type: String, attribute: "show-curl-before-try" }) showCurlBeforeTry = "false";
100
+
101
+ // Main Colors and Font
102
+ @property({ type: String, reflect: true }) theme = DEFAULT_THEME;
103
+ @property({ type: String, attribute: "primary-color" }) primaryColor = "";
104
+ @property({ type: String, attribute: "color-scheme", reflect: true }) colorScheme = "dark";
105
+ // color-scheme="auto": follows the page's theme (see utils/auto-color-scheme.js)
106
+ _autoColorScheme = new AutoColorSchemeController(this);
107
+ @property({ type: String, reflect: true }) radius = "sm";
108
+ @property({ type: String, reflect: true }) scale = "default";
109
+
110
+ // Fetch Options
111
+ @property({ type: String, attribute: "fetch-credentials" }) fetchCredentials = "";
112
+
113
+ // Filters
114
+ @property({ type: String, attribute: "match-paths" }) matchPaths = "";
115
+ @property({ type: String, attribute: "match-type" }) matchType = "includes";
116
+ @property({ type: String, attribute: "remove-endpoints-with-badge-label-as" })
117
+ removeEndpointsWithBadgeLabelAs = "";
118
+
119
+ // Internal Properties
120
+ @property({ type: Boolean }) loading = false;
121
+
122
+ isMini: boolean;
123
+ updateRoute: string;
124
+ renderStyle: string;
125
+ showHeader: string;
126
+ allowAdvancedSearch: string;
127
+ resolvedSpec: any;
128
+ selectedServer: any;
129
+ loadFailed: boolean;
130
+ sortTags: any;
131
+ generateMissingTags: any;
132
+ sortSchemas: any;
133
+ allowSchemaDescriptionExpandToggle: any;
134
+
135
+ constructor() {
136
+ super();
137
+ this.isMini = true;
138
+ this.updateRoute = "false";
139
+ this.renderStyle = "view";
140
+ this.showHeader = "false";
141
+ this.allowAdvancedSearch = "false";
142
+ this.loadFailed = false;
143
+ }
144
+
145
+ static get styles() {
146
+ return [
147
+ ThemeTokens,
148
+ FontStyles,
149
+ InputStyles,
150
+ FlexStyles,
151
+ AuthStyles,
152
+ ParamListStyles,
153
+ EndpointStyles,
154
+ MicrolighterStyles,
155
+ TabStyles,
156
+ NavStyles,
157
+ InfoStyles,
158
+ css`
159
+ :host {
160
+ all: initial;
161
+ /* Same crisp text rendering as <rapi-doc> (see layout-styles.js) */
162
+ -webkit-font-smoothing: antialiased;
163
+ -moz-osx-font-smoothing: grayscale;
164
+ display: flex;
165
+ flex-direction: column;
166
+ min-width: 360px;
167
+ width: 100%;
168
+ height: 100%;
169
+ margin: 0;
170
+ padding: 0;
171
+ overflow: hidden;
172
+ letter-spacing: normal;
173
+ color: var(--foreground);
174
+ background: var(--background);
175
+ font-family: var(--font-sans);
176
+ container-type: inline-size;
177
+ }
178
+
179
+ @container (min-width: 768px) {
180
+ .only-large-screen {
181
+ display: block;
182
+ }
183
+ .only-large-screen-flex {
184
+ display: flex;
185
+ }
186
+ }
187
+ `,
188
+ ];
189
+ }
190
+
191
+ // Startup
192
+ connectedCallback() {
193
+ super.connectedCallback();
194
+
195
+ if (
196
+ !this.showSummaryWhenCollapsed ||
197
+ !"true, false,".includes(`${this.showSummaryWhenCollapsed},`)
198
+ ) {
199
+ this.showSummaryWhenCollapsed = "true";
200
+ }
201
+ if (!this.layout || !"row, column,".includes(`${this.layout},`)) {
202
+ this.layout = "row";
203
+ }
204
+ if (!this.schemaStyle || !"tree, table,".includes(`${this.schemaStyle},`)) {
205
+ this.schemaStyle = "tree";
206
+ }
207
+ if (this.primaryColor && isValidHexColor(this.primaryColor)) {
208
+ this.theme = this.primaryColor;
209
+ }
210
+ const normalizedTheme = normalizeTheme(this.theme);
211
+ this.theme = normalizedTheme.theme;
212
+ this.setAttribute("theme", this.theme);
213
+ if (!this.colorScheme || !"dark, light, system,".includes(`${this.colorScheme},`)) {
214
+ this.colorScheme = "dark";
215
+ }
216
+ if (!this.radius || !"none, sm, md, lg, full,".includes(`${this.radius},`)) {
217
+ this.radius = "sm";
218
+ }
219
+ if (!this.scale || !"sm, default, lg,".includes(`${this.scale},`)) {
220
+ this.scale = "default";
221
+ }
222
+ if (!this.getAttribute("theme")) {
223
+ this.setAttribute("theme", this.theme);
224
+ }
225
+ if (!this.getAttribute("color-scheme")) {
226
+ this.setAttribute("color-scheme", this.colorScheme);
227
+ }
228
+ if (!this.getAttribute("radius")) {
229
+ this.setAttribute("radius", this.radius);
230
+ }
231
+ if (!this.getAttribute("scale")) {
232
+ this.setAttribute("scale", this.scale);
233
+ }
234
+ applyCustomTheme(this, this.theme);
235
+ if (
236
+ !this.defaultSchemaTab ||
237
+ !"example, schema, model,".includes(`${this.defaultSchemaTab},`)
238
+ ) {
239
+ this.defaultSchemaTab = "example";
240
+ } else if (this.defaultSchemaTab === "model") {
241
+ this.defaultSchemaTab = "schema";
242
+ }
243
+ this.pathsExpanded = this.pathsExpanded === "true";
244
+ if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) {
245
+ this.schemaExpandLevel = 99999;
246
+ }
247
+ if (
248
+ !this.schemaDescriptionExpanded ||
249
+ !"true, false,".includes(`${this.schemaDescriptionExpanded},`)
250
+ ) {
251
+ this.schemaDescriptionExpanded = "false";
252
+ }
253
+ if (
254
+ !this.fillRequestFieldsWithExample ||
255
+ !"true, false,".includes(`${this.fillRequestFieldsWithExample},`)
256
+ ) {
257
+ this.fillRequestFieldsWithExample = "true";
258
+ }
259
+ if (!this.persistAuth || !"true, false,".includes(`${this.persistAuth},`)) {
260
+ this.persistAuth = "false";
261
+ }
262
+ if (!this.responseAreaHeight) {
263
+ this.responseAreaHeight = "300px";
264
+ }
265
+
266
+ if (!this.allowTry || !"true, false,".includes(`${this.allowTry},`)) {
267
+ this.allowTry = "true";
268
+ }
269
+ if (!this.apiKeyValue) {
270
+ this.apiKeyValue = "-";
271
+ }
272
+ if (!this.apiKeyLocation) {
273
+ this.apiKeyLocation = "header";
274
+ }
275
+ if (!this.apiKeyName) {
276
+ this.apiKeyName = "";
277
+ }
278
+
279
+ if (!this.oauthReceiver) {
280
+ this.oauthReceiver = "oauth-receiver.html";
281
+ }
282
+ if (!this.sortTags || !"true, false,".includes(`${this.sortTags},`)) {
283
+ this.sortTags = "false";
284
+ }
285
+ if (!this.sortEndpointsBy || !"method, path, summary,".includes(`${this.sortEndpointsBy},`)) {
286
+ this.sortEndpointsBy = "path";
287
+ }
288
+
289
+ if (!this.matchType || !"includes regex".includes(this.matchType)) {
290
+ this.matchType = "includes";
291
+ }
292
+ if (!this.matchPaths) {
293
+ this.matchPaths = "";
294
+ }
295
+ if (!this.removeEndpointsWithBadgeLabelAs) {
296
+ this.removeEndpointsWithBadgeLabelAs = "";
297
+ }
298
+
299
+ if (
300
+ !this.allowSchemaDescriptionExpandToggle ||
301
+ !"true, false,".includes(`${this.allowSchemaDescriptionExpandToggle},`)
302
+ ) {
303
+ this.allowSchemaDescriptionExpandToggle = "true";
304
+ }
305
+ if (
306
+ !this.fetchCredentials ||
307
+ !"omit, same-origin, include,".includes(`${this.fetchCredentials},`)
308
+ ) {
309
+ this.fetchCredentials = "";
310
+ }
311
+ }
312
+
313
+ disconnectedCallback() {
314
+ if (this.mockServer === "true") {
315
+ disableMockServer();
316
+ }
317
+ super.disconnectedCallback();
318
+ }
319
+
320
+ render() {
321
+ return mainBodyTemplate.call(this, true, this.pathsExpanded);
322
+ }
323
+
324
+ get config() {
325
+ return {
326
+ renderStyle: this.renderStyle,
327
+ schemaStyle: this.schemaStyle,
328
+ defaultSchemaTab: this.defaultSchemaTab,
329
+ schemaExpandLevel: this.schemaExpandLevel,
330
+ schemaDescriptionExpanded: this.schemaDescriptionExpanded,
331
+ allowSchemaDescriptionExpandToggle: this.allowSchemaDescriptionExpandToggle,
332
+ schemaHideReadOnly: this.schemaHideReadOnly,
333
+ schemaHideWriteOnly: this.schemaHideWriteOnly,
334
+ fillRequestFieldsWithExample: this.fillRequestFieldsWithExample,
335
+ allowTry: this.allowTry,
336
+ showCurlBeforeTry: this.showCurlBeforeTry,
337
+ fetchCredentials: this.fetchCredentials,
338
+ };
339
+ }
340
+
341
+ updated(changedProperties) {
342
+ super.updated?.(changedProperties);
343
+ scheduleHighlight(this.shadowRoot);
344
+
345
+ if (changedProperties.has("theme")) {
346
+ const normalizedTheme = normalizeTheme(this.theme);
347
+ if (this.theme !== normalizedTheme.theme) {
348
+ this.theme = normalizedTheme.theme;
349
+ this.setAttribute("theme", this.theme);
350
+ }
351
+ applyCustomTheme(this, this.theme);
352
+ }
353
+
354
+ if (
355
+ changedProperties.has("primaryColor") &&
356
+ this.primaryColor &&
357
+ isValidHexColor(this.primaryColor)
358
+ ) {
359
+ this.theme = normalizeTheme(this.primaryColor).theme;
360
+ this.setAttribute("theme", this.theme);
361
+ applyCustomTheme(this, this.theme);
362
+ }
363
+
364
+ if (changedProperties.has("mockServer")) {
365
+ if (this.mockServer === "true" && this.resolvedSpec) {
366
+ enableMockServer(this.resolvedSpec, {
367
+ statusCode: this.mockServerStatusCode,
368
+ statusStrategy: this.mockServerStatusStrategy,
369
+ delay: this.mockServerDelay,
370
+ log: this.mockServerLog,
371
+ });
372
+ } else if (this.mockServer !== "true") {
373
+ disableMockServer();
374
+ }
375
+ }
376
+ if (
377
+ changedProperties.has("mockServerStatusCode") ||
378
+ changedProperties.has("mockServerStatusStrategy") ||
379
+ changedProperties.has("mockServerDelay") ||
380
+ changedProperties.has("mockServerLog")
381
+ ) {
382
+ updateMockConfig({
383
+ statusCode: this.mockServerStatusCode,
384
+ statusStrategy: this.mockServerStatusStrategy,
385
+ delay: this.mockServerDelay,
386
+ log: this.mockServerLog,
387
+ });
388
+ }
389
+ }
390
+
391
+ attributeChangedCallback(name, oldVal, newVal) {
392
+ if (name === "spec-url") {
393
+ if (oldVal !== newVal) {
394
+ // put it at the end of event-loop to load all the attributes
395
+ window.setTimeout(async () => {
396
+ await this.loadSpec(newVal);
397
+ }, 0);
398
+ }
399
+ }
400
+ if (
401
+ name === "match-paths" ||
402
+ name === "match-type" ||
403
+ name === "remove-endpoints-with-badge-label-as"
404
+ ) {
405
+ if (oldVal !== newVal) {
406
+ window.setTimeout(async () => {
407
+ await this.loadSpec(this.specUrl);
408
+ }, 0);
409
+ }
410
+ }
411
+ if (name === "api-key-name" || name === "api-key-location" || name === "api-key-value") {
412
+ let updateSelectedApiKey = false;
413
+ let apiKeyName = "";
414
+ let apiKeyLocation = "";
415
+ let apiKeyValue = "";
416
+
417
+ if (name === "api-key-name") {
418
+ if (this.getAttribute("api-key-location") && this.getAttribute("api-key-value")) {
419
+ apiKeyName = newVal;
420
+ apiKeyLocation = this.getAttribute("api-key-location");
421
+ apiKeyValue = this.getAttribute("api-key-value");
422
+ updateSelectedApiKey = true;
423
+ }
424
+ } else if (name === "api-key-location") {
425
+ if (this.getAttribute("api-key-name") && this.getAttribute("api-key-value")) {
426
+ apiKeyLocation = newVal;
427
+ apiKeyName = this.getAttribute("api-key-name");
428
+ apiKeyValue = this.getAttribute("api-key-value");
429
+ updateSelectedApiKey = true;
430
+ }
431
+ } else if (name === "api-key-value") {
432
+ if (this.getAttribute("api-key-name") && this.getAttribute("api-key-location")) {
433
+ apiKeyValue = newVal;
434
+ apiKeyLocation = this.getAttribute("api-key-location");
435
+ apiKeyName = this.getAttribute("api-key-name");
436
+ updateSelectedApiKey = true;
437
+ }
438
+ }
439
+
440
+ if (updateSelectedApiKey) {
441
+ if (this.resolvedSpec) {
442
+ const rapiDocApiKey = this.resolvedSpec.securitySchemes.find(
443
+ (v: any) => v.securitySchemeId === rapidocApiKey,
444
+ );
445
+ if (!rapiDocApiKey) {
446
+ this.resolvedSpec.securitySchemes.push({
447
+ securitySchemeId: rapidocApiKey,
448
+ description: "api-key provided in rapidoc element attributes",
449
+ type: "apiKey",
450
+ name: apiKeyName,
451
+ in: apiKeyLocation,
452
+ value: apiKeyValue,
453
+ finalKeyValue: apiKeyValue,
454
+ });
455
+ } else {
456
+ rapiDocApiKey.name = apiKeyName;
457
+ rapiDocApiKey.in = apiKeyLocation;
458
+ rapiDocApiKey.value = apiKeyValue;
459
+ rapiDocApiKey.finalKeyValue = apiKeyValue;
460
+ }
461
+ this.requestUpdate();
462
+ }
463
+ }
464
+ }
465
+ super.attributeChangedCallback(name, oldVal, newVal);
466
+ }
467
+
468
+ onSpecUrlChange() {
469
+ this.setAttribute("spec-url", (this.shadowRoot.getElementById("spec-url") as any).value);
470
+ }
471
+
472
+ // Public Method
473
+ async loadSpec(specUrl) {
474
+ if (!specUrl) {
475
+ return;
476
+ }
477
+ try {
478
+ this.resolvedSpec = {
479
+ specLoadError: false,
480
+ isSpecLoading: true,
481
+ tags: [],
482
+ };
483
+ this.loading = true;
484
+ this.loadFailed = false;
485
+ this.requestUpdate();
486
+ const spec = await ProcessSpec.call(
487
+ this,
488
+ specUrl,
489
+ this.generateMissingTags === "true",
490
+ this.sortTags === "true",
491
+ this.sortSchemas === "true",
492
+ this.getAttribute("sort-endpoints-by"),
493
+ this.getAttribute("api-key-name"),
494
+ this.getAttribute("api-key-location"),
495
+ this.getAttribute("api-key-value"),
496
+ this.getAttribute("server-url"),
497
+ this.matchPaths,
498
+ this.matchType,
499
+ this.removeEndpointsWithBadgeLabelAs,
500
+ );
501
+ this.loading = false;
502
+ this.afterSpecParsedAndValidated(spec);
503
+ } catch (err: any) {
504
+ this.loading = false;
505
+ this.loadFailed = true;
506
+ this.resolvedSpec = null;
507
+ console.error(`RapiDoc: Unable to resolve the API spec.. ${err.message}`);
508
+ }
509
+ }
510
+
511
+ // Public Method - to update security-scheme of type http
512
+ setHttpUserNameAndPassword(securitySchemeId, username, password) {
513
+ return applyApiKey.call(this, securitySchemeId, username, password);
514
+ }
515
+
516
+ // Public Method - to update security-scheme of type apiKey or OAuth.
517
+ // options.note: where the key came from (e.g. "Using your sign-in"), shown in place of the scheme's form
518
+ setApiKey(securitySchemeId, apiKeyValue, options: { note?: string } = {}) {
519
+ return applyApiKey.call(this, securitySchemeId, "", "", apiKeyValue, options?.note || "");
520
+ }
521
+
522
+ // Public Method
523
+ removeAllSecurityKeys() {
524
+ return onClearAllApiKeys.call(this);
525
+ }
526
+
527
+ // Public Method
528
+ setApiServer(apiServerUrl) {
529
+ // return apiServerUrl;
530
+ return setApiServer.call(this, apiServerUrl);
531
+ }
532
+
533
+ async afterSpecParsedAndValidated(spec) {
534
+ this.resolvedSpec = spec;
535
+ this.selectedServer = undefined;
536
+ if (this.defaultApiServerUrl) {
537
+ if (this.defaultApiServerUrl === this.serverUrl) {
538
+ this.selectedServer = {
539
+ url: this.serverUrl,
540
+ computedUrl: this.serverUrl,
541
+ };
542
+ } else if (this.resolvedSpec.servers) {
543
+ this.selectedServer = this.resolvedSpec.servers.find(
544
+ (v: any) => v.url === this.defaultApiServerUrl,
545
+ );
546
+ }
547
+ }
548
+ if (!this.selectedServer) {
549
+ if (this.resolvedSpec.servers) {
550
+ this.selectedServer = this.resolvedSpec.servers[0];
551
+ }
552
+ }
553
+ this.requestUpdate();
554
+
555
+ while (!(await this.updateComplete));
556
+ const specLoadedEvent = new CustomEvent("spec-loaded", { detail: spec });
557
+ this.dispatchEvent(specLoadedEvent);
558
+
559
+ if (this.mockServer === "true") {
560
+ enableMockServer(this.resolvedSpec, {
561
+ statusCode: this.mockServerStatusCode,
562
+ statusStrategy: this.mockServerStatusStrategy,
563
+ delay: this.mockServerDelay,
564
+ log: this.mockServerLog,
565
+ });
566
+ }
567
+ }
568
+
569
+ // Called by anchor tags created using markdown
570
+ handleHref(e) {
571
+ if (e.target.tagName.toLowerCase() === "a") {
572
+ if (e.target.getAttribute("href").startsWith("#")) {
573
+ const gotoEl = this.shadowRoot.getElementById(
574
+ e.target.getAttribute("href").replace("#", ""),
575
+ );
576
+ if (gotoEl) {
577
+ gotoEl.scrollIntoView({ behavior: "auto", block: "start" });
578
+ }
579
+ }
580
+ }
581
+ }
582
+ }