import { css, LitElement } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { scheduleHighlight } from "~/utils/highlighter"; // Styles import FontStyles from "~/styles/font-styles"; import InputStyles from "~/styles/input-styles"; import FlexStyles from "~/styles/flex-styles"; import AuthStyles from "~/styles/auth-styles"; import ParamListStyles from "~/styles/param-list-styles"; import MicrolighterStyles from "~/styles/microlighter-styles"; import TabStyles from "~/styles/tab-styles"; import NavStyles from "~/styles/nav-styles"; import InfoStyles from "~/styles/info-styles"; import EndpointStyles from "~/styles/endpoint-styles"; import ThemeTokens, { DEFAULT_THEME, applyCustomTheme, isValidHexColor, normalizeTheme, } from "~/styles/theme-tokens"; import { rapidocApiKey } from "~/utils/common-utils"; import ProcessSpec from "~/utils/spec-parser"; import { enableMockServer, disableMockServer, updateMockConfig } from "~/utils/mock-interceptor"; import mainBodyTemplate from "~/templates/main-body-template"; import { applyApiKey, onClearAllApiKeys, recoverPersistedApiKeys, } from "~/templates/security-scheme-template"; import { setApiServer } from "~/templates/server-template"; import "~/utils/markdown-utils"; import { AutoColorSchemeController } from "~/utils/auto-color-scheme"; const paramsConverter = { fromAttribute: (attr: string | null) => { if (!attr) { return null; } const trimmed = attr.trim(); if (trimmed.startsWith("{") && trimmed.endsWith("}")) { try { return JSON.parse(trimmed); } catch { return trimmed; } } return trimmed; }, toAttribute: (prop: any) => { if (typeof prop === "object" && prop !== null) { return JSON.stringify(prop); } return prop; }, }; /** * ``: the operations you pick from an OpenAPI document, with their parameters, * schemas and Try console, without navigation or search. Its doc comments are read like those of * `` (see the class comment in rapidoc.ts) into the custom elements manifest and the * types in dist/. * * @fires spec-loaded - Dispatched after the OpenAPI specification has been fully fetched, parsed, * resolved, and rendered into the DOM. Provides the resolved spec object in e.detail. */ @customElement("rapi-doc-mini") export default class RapiDocMini extends LitElement { /** * URL of the OpenAPI specification file (JSON or YAML) to load and render. * @group Spec & Content */ @property({ type: String, attribute: "spec-url" }) specUrl = ""; /** * Sorts endpoints within each tag group by path, HTTP method, or summary. 'none' leaves the sort * order unmodified.
ⓘ This is a static initialization attribute. It will * not have any effect if modified using JavaScript after the spec is rendered. * @group Spec & Content */ @property({ type: String, attribute: "sort-endpoints-by" }) sortEndpointsBy: "path" | "method" | "summary" | "none" = "path"; /** * Request and response side by side (row), or one above the * other (column). * @group Layout & Scrolling */ @property({ type: String }) layout: "row" | "column" = "row"; /** * Shows operations open instead of collapsed. * @group Layout & Scrolling */ @property({ type: String, attribute: "paths-expanded" }) pathsExpanded: "true" | "false" | boolean = "false"; /** * Selects which tab is active by default, and listed first, for request bodies, responses and * object parameters: 'schema' (data contract model) or 'example' (sample JSON payload). * @summary Default active tab in request and response bodies * @group Schemas */ @property({ type: String, attribute: "default-schema-tab" }) defaultSchemaTab: "schema" | "example" = "example"; /** * Height of the response panel, as a CSS length. * @group Layout & Scrolling */ @property({ type: String, attribute: "response-area-height" }) responseAreaHeight = "300px"; /** * Shows the summary on a collapsed operation. * @group Layout & Scrolling */ @property({ type: String, attribute: "show-summary-when-collapsed" }) showSummaryWhenCollapsed: "true" | "false" = "true"; /** * Pre-populates interactive request parameter inputs and request body fields using example values * defined in the OpenAPI spec. * @summary Pre-populate "Try" console parameters with sample values * @group Try & Servers */ @property({ type: String, attribute: "fill-request-fields-with-example" }) fillRequestFieldsWithExample: "true" | "false" = "true"; /** * Keeps API keys, bearer tokens and OAuth access tokens in localStorage across page reloads; an * OAuth token is dropped once it expires. Basic credentials and OAuth client secrets are never * stored. * @summary Persist API keys and tokens in browser localStorage * @group Authentication */ @property({ type: String, attribute: "persist-auth" }) persistAuth: "true" | "false" = "false"; /** * Controls the visual representation of complex JSON schemas in request and response panels. * 'tree' provides an interactive collapsible tree view; 'table' renders structured tabular rows. * @summary Display schemas as visual table or tree hierarchy * @group Schemas */ @property({ type: String, attribute: "schema-style" }) schemaStyle: "tree" | "table" = "tree"; /** * Initial depth level for auto-expanding complex nested schema properties and sub-objects (the * default expands all levels). * @summary Initial expansion depth for nested schemas * @group Schemas */ @property({ type: Number, attribute: "schema-expand-level" }) schemaExpandLevel = 99999; /** * Controls whether schema field constraints, validation rules, and descriptions are fully * expanded by default or collapsed to a single line. * @summary Display full multiline schema property descriptions by default * @group Schemas */ @property({ type: String, attribute: "schema-description-expanded" }) schemaDescriptionExpanded: "true" | "false" = "false"; /** * Name of the header or query parameter used when transmitting the API key in interactive console * requests. * @group Authentication */ @property({ type: String, attribute: "api-key-name" }) apiKeyName = ""; /** * Specifies whether the API key is passed as an HTTP request header or query parameter. * @group Authentication */ @property({ type: String, attribute: "api-key-location" }) apiKeyLocation: "header" | "query" = "header"; /** * Pre-configured API key value sent during interactive console requests. Can also be set or * overwritten directly in the UI. * @group Authentication * @default (empty) */ @property({ type: String, attribute: "api-key-value" }) apiKeyValue = ""; /** * Selects which server URL from the spec's servers list should be selected by default. * @group Try & Servers */ @property({ type: String, attribute: "default-api-server" }) defaultApiServerUrl = ""; /** * Custom API server base URL. Overrides the servers array defined in the OpenAPI specification. * Particularly useful when sharing a single spec across development, staging, and production * environments. * @group Try & Servers */ @property({ type: String, attribute: "server-url" }) serverUrl = ""; /** * Relative or absolute path to the OAuth receiver HTML file for handling authorization * redirection callbacks. * @group Authentication */ @property({ type: String, attribute: "oauth-receiver" }) oauthReceiver = "oauth-receiver.html"; /** * Custom query parameters appended to the OAuth2 authorization URL query string (e.g. proxy * launch tokens, prompt, audience).

Supported Formats: * @group Authentication * @default (empty) */ @property({ type: Object, attribute: "additional-authorize-params", converter: paramsConverter }) additionalAuthorizeParams: any; /** * Custom parameters included in the POST request body sent to the OAuth2 token endpoint (e.g. * custom proxy parameters, resource, audience).

Supported Formats: * * @group Authentication * @default (empty) */ @property({ type: Object, attribute: "additional-token-params", converter: paramsConverter }) additionalTokenParams: any; /** * Enables the built-in, zero-dependency in-browser mock server. Transparently intercepts outgoing * network requests (both RapiDoc's Try console and host application fetch/XHR calls) and serves * mock responses based on OpenAPI examples or generated from schemas. * @summary Answer Try requests from the in-browser mock server * @group Mock Server */ @property({ type: String, attribute: "mock-server" }) mockServer: "true" | "false" = "false"; // A string of codes for every operation, or a map by operation (`{ "POST /orders": "503, 200", "*": "200" }`) /** * HTTP status code to answer with, or several separated by commas, used in turn per operation * (503, 503, 200: two failures, then a success); a random: prefix picks one at random for each call (random:200, 500), cycle: says in turn * explicitly. Or a JSON map by operation, each with its own codes and prefix ({ "POST /orders": "cycle:503, 200", "*": "200" }). Set it to an empty string to * use the first 2xx response in the spec. * @group Mock Server */ @property({ type: String, attribute: "mock-server-status-code" }) mockServerStatusCode: string | Record = "200"; /** * Simulated network latency in milliseconds before resolving mock responses. Useful for testing * client loading spinners and optimistic UI updates. * @group Mock Server */ @property({ type: Number, attribute: "mock-server-delay" }) mockServerDelay = 0; /** * Logs one line per answered request (method, path and status code) to the browser console. * @group Mock Server */ @property({ type: String, attribute: "mock-server-log" }) mockServerLog: "true" | "false" = "false"; /** * Enables the interactive "TRY" console allowing users to test live API calls directly from their * browser. Besides true and false, it takes the terms of filter-operations * to turn Try on only for the operations they select: !deprecated * !tag:pending-implementation keeps it off for deprecated operations and those tagged * pending-implementation. The others keep their request documentation and show a disabled TRY * DISABLED button. The Authentication section stays usable unless it is false. * @summary Live interactive endpoint testing console * @group Try & Servers * @allowedNote (or filter-operations terms, e.g. !deprecated) */ @property({ type: String, attribute: "allow-try" }) allowTry: "true" | "false" | (string & {}) = "true"; /** * When set to true, generates and displays copyable cURL * commands directly within the endpoint documentation prior to clicking "TRY". * @summary Display cURL command before invoking API * @group Try & Servers */ @property({ type: String, attribute: "show-curl-before-try" }) showCurlBeforeTry: "true" | "false" = "false"; /** * Brand color preset, or a custom brand color as a hex code. Each preset defines a dark and a * light palette. * @summary Color palette preset * @group Theme * @allowedNote (or custom hex color e.g. #2563eb) * @default amber */ @property({ type: String, reflect: true }) theme: "ember" | "carbon" | "cobalt" | "jade" | "indigo" | "amber" | (string & {}) = DEFAULT_THEME; /** * A custom brand color as a hex code. Same as passing the hex code to theme. * @group Theme * @hidden */ @property({ type: String, attribute: "primary-color" }) primaryColor = ""; /** * Base color scheme mode. 'system' automatically matches the user's OS preference. 'auto' follows * the host page: it reads the page's CSS color-scheme (for example * :root[data-theme='light'] { color-scheme: light }, as Starlight sets it) and * updates when the page switches theme; when the page declares none, it falls back to the OS * preference. * @summary Dark, light, or follow the system or the page * @group Theme */ @property({ type: String, attribute: "color-scheme", reflect: true }) colorScheme: "dark" | "light" | "system" | "auto" = "dark"; // color-scheme="auto": follows the page's theme (see utils/auto-color-scheme.js) _autoColorScheme = new AutoColorSchemeController(this); /** * Corner radius scale applied across cards, buttons, badges, inputs, and dialogs. * @summary Border radius for cards, inputs, and buttons * @group Theme */ @property({ type: String, reflect: true }) radius: "none" | "sm" | "md" | "lg" | "full" = "sm"; /** * Relative scale factor for typography and UI elements across the documentation portal. * @summary Global scale for typography and spacing * @group Theme */ @property({ type: String, reflect: true }) scale: "sm" | "default" | "lg" = "default"; /** * Configures credentials mode for cross-origin browser Fetch requests as defined in the Fetch Standard, enabling transmission of cookies and Authorization headers * in CORS requests. * @group Try & Servers */ @property({ type: String, attribute: "fetch-credentials" }) fetchCredentials: "" | "omit" | "same-origin" | "include" = ""; /** * Which operations to show: a space- or comma-separated list of terms. An operation is shown when * it matches any include term (every one is, without one) and no ! term. A term is an operationId (getPetById), a * method and path (GET /pet/{petId}), a path for all its methods, * a path glob (/pet/**; * is one * segment, ** any number), tag:store, badge:Beta (an x-badges label, or an OpenAPI 3.2 tag of kind: badge) or * deprecated; ! before a term * leaves out what it matches (!badge:Internal). Shown operations * keep the order of the first term they match, so a list of operationIds shows them in that * order (unless sort-endpoints-by is set). * @summary Show only some operations * @group Spec & Content */ @property({ type: String, attribute: "filter-operations" }) filterOperations = ""; /** * true shows each tag's name and description above its * operations. Off by default: a mini usually shows a few of a tag's operations, which its * description would not match. <rapi-doc> always shows * tags. * @summary Show tag names and descriptions * @group Spec & Content */ @property({ type: String, attribute: "show-tags" }) showTags: "true" | "false" = "false"; @state() loading = false; isMini: boolean; _specLoadSeq: number; _lastLoadedSpec: any; updateRoute: string; renderStyle: string; showHeader: string; allowAdvancedSearch: string; resolvedSpec: any; selectedServer: any; loadFailed: boolean; sortTags: any; generateMissingTags: any; sortSchemas: any; allowSchemaDescriptionExpandToggle: any; constructor() { super(); this.isMini = true; // Spec loads carry a token; only the latest load may apply its result (see loadSpec) this._specLoadSeq = 0; this.updateRoute = "false"; this.renderStyle = "view"; this.showHeader = "false"; this.allowAdvancedSearch = "false"; this.loadFailed = false; } static get styles() { return [ ThemeTokens, FontStyles, InputStyles, FlexStyles, AuthStyles, ParamListStyles, EndpointStyles, MicrolighterStyles, TabStyles, NavStyles, InfoStyles, css` :host { all: initial; /* Same crisp text rendering as (see layout-styles.js) */ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; display: flex; flex-direction: column; min-width: 360px; width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; letter-spacing: normal; color: var(--foreground); background: var(--background); font-family: var(--font-sans); container-type: inline-size; } @container (min-width: 768px) { .only-large-screen { display: block; } .only-large-screen-flex { display: flex; } } `, ]; } // Startup connectedCallback() { super.connectedCallback(); if ( !this.showSummaryWhenCollapsed || !"true, false,".includes(`${this.showSummaryWhenCollapsed},`) ) { this.showSummaryWhenCollapsed = "true"; } if (!this.layout || !"row, column,".includes(`${this.layout},`)) { this.layout = "row"; } if (!this.schemaStyle || !"tree, table,".includes(`${this.schemaStyle},`)) { this.schemaStyle = "tree"; } if (this.primaryColor && isValidHexColor(this.primaryColor)) { this.theme = this.primaryColor; } const normalizedTheme = normalizeTheme(this.theme); this.theme = normalizedTheme.theme; this.setAttribute("theme", this.theme); if (!this.colorScheme || !"dark, light, system,".includes(`${this.colorScheme},`)) { this.colorScheme = "dark"; } if (!this.radius || !"none, sm, md, lg, full,".includes(`${this.radius},`)) { this.radius = "sm"; } if (!this.scale || !"sm, default, lg,".includes(`${this.scale},`)) { this.scale = "default"; } if (!this.getAttribute("theme")) { this.setAttribute("theme", this.theme); } if (!this.getAttribute("color-scheme")) { this.setAttribute("color-scheme", this.colorScheme); } if (!this.getAttribute("radius")) { this.setAttribute("radius", this.radius); } if (!this.getAttribute("scale")) { this.setAttribute("scale", this.scale); } applyCustomTheme(this, this.theme); if (!this.defaultSchemaTab || !"example, schema,".includes(`${this.defaultSchemaTab},`)) { this.defaultSchemaTab = "example"; } this.pathsExpanded = this.pathsExpanded === "true"; if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; } if ( !this.schemaDescriptionExpanded || !"true, false,".includes(`${this.schemaDescriptionExpanded},`) ) { this.schemaDescriptionExpanded = "false"; } if ( !this.fillRequestFieldsWithExample || !"true, false,".includes(`${this.fillRequestFieldsWithExample},`) ) { this.fillRequestFieldsWithExample = "true"; } if (!this.persistAuth || !"true, false,".includes(`${this.persistAuth},`)) { this.persistAuth = "false"; } if (!this.responseAreaHeight) { this.responseAreaHeight = "300px"; } // "true", "false", or filter-operations terms (utils/try-filter.js) if (!this.allowTry || !String(this.allowTry).trim()) { this.allowTry = "true"; } if (!this.apiKeyLocation) { this.apiKeyLocation = "header"; } if (!this.apiKeyName) { this.apiKeyName = ""; } if (!this.oauthReceiver) { this.oauthReceiver = "oauth-receiver.html"; } if (!this.sortTags || !"true, false,".includes(`${this.sortTags},`)) { this.sortTags = "false"; } if (!this.sortEndpointsBy || !"method, path, summary,".includes(`${this.sortEndpointsBy},`)) { this.sortEndpointsBy = "path"; } if ( !this.allowSchemaDescriptionExpandToggle || !"true, false,".includes(`${this.allowSchemaDescriptionExpandToggle},`) ) { this.allowSchemaDescriptionExpandToggle = "true"; } if ( !this.fetchCredentials || !"omit, same-origin, include,".includes(`${this.fetchCredentials},`) ) { this.fetchCredentials = ""; } // Moved in the page (disconnected, then connected again): disconnectedCallback turned the mock off if (this.mockServer === "true" && this.resolvedSpec?.tags && !this.resolvedSpec.isSpecLoading) { this.enableMock(); } } // Answers this element's Try requests (and the page's calls to the spec's servers) from the mock enableMock() { enableMockServer(this.resolvedSpec, { owner: this, statusCode: this.mockServerStatusCode, delay: this.mockServerDelay, log: this.mockServerLog, }); } disconnectedCallback() { if (this.mockServer === "true") { disableMockServer(this); } super.disconnectedCallback(); } render() { return mainBodyTemplate.call(this, true, this.pathsExpanded); } get config() { return { renderStyle: this.renderStyle, schemaStyle: this.schemaStyle, defaultSchemaTab: this.defaultSchemaTab, schemaExpandLevel: this.schemaExpandLevel, schemaDescriptionExpanded: this.schemaDescriptionExpanded, allowSchemaDescriptionExpandToggle: this.allowSchemaDescriptionExpandToggle, schemaHideReadOnly: this.schemaHideReadOnly, schemaHideWriteOnly: this.schemaHideWriteOnly, fillRequestFieldsWithExample: this.fillRequestFieldsWithExample, allowTry: this.allowTry, showCurlBeforeTry: this.showCurlBeforeTry, fetchCredentials: this.fetchCredentials, // The Try button reads "TRY (Mock)" while the in-browser mock answers mockServer: this.mockServer, }; } updated(changedProperties) { super.updated?.(changedProperties); scheduleHighlight(this.shadowRoot); if (changedProperties.has("theme")) { const normalizedTheme = normalizeTheme(this.theme); if (this.theme !== normalizedTheme.theme) { this.theme = normalizedTheme.theme; this.setAttribute("theme", this.theme); } applyCustomTheme(this, this.theme); } if ( changedProperties.has("primaryColor") && this.primaryColor && isValidHexColor(this.primaryColor) ) { this.theme = normalizeTheme(this.primaryColor).theme; this.setAttribute("theme", this.theme); applyCustomTheme(this, this.theme); } if (changedProperties.has("mockServer")) { if (this.mockServer === "true" && this.resolvedSpec) { this.enableMock(); } else if (this.mockServer !== "true") { disableMockServer(this); } } if ( changedProperties.has("mockServerStatusCode") || changedProperties.has("mockServerDelay") || changedProperties.has("mockServerLog") ) { updateMockConfig({ owner: this, statusCode: this.mockServerStatusCode, delay: this.mockServerDelay, log: this.mockServerLog, }); } } attributeChangedCallback(name, oldVal, newVal) { if (name === "spec-url" && oldVal !== newVal) { this.queueLoad({ spec: newVal }); } if (name === "filter-operations" && oldVal !== newVal) { this.queueLoad(); } if (name === "api-key-name" || name === "api-key-location" || name === "api-key-value") { let updateSelectedApiKey = false; let apiKeyName = ""; let apiKeyLocation = ""; let apiKeyValue = ""; if (name === "api-key-name") { if (this.getAttribute("api-key-location") && this.getAttribute("api-key-value")) { apiKeyName = newVal; apiKeyLocation = this.getAttribute("api-key-location"); apiKeyValue = this.getAttribute("api-key-value"); updateSelectedApiKey = true; } } else if (name === "api-key-location") { if (this.getAttribute("api-key-name") && this.getAttribute("api-key-value")) { apiKeyLocation = newVal; apiKeyName = this.getAttribute("api-key-name"); apiKeyValue = this.getAttribute("api-key-value"); updateSelectedApiKey = true; } } else if (name === "api-key-value") { if (this.getAttribute("api-key-name") && this.getAttribute("api-key-location")) { apiKeyValue = newVal; apiKeyLocation = this.getAttribute("api-key-location"); apiKeyName = this.getAttribute("api-key-name"); updateSelectedApiKey = true; } } if (updateSelectedApiKey) { // While the spec is loading, resolvedSpec is a placeholder without securitySchemes if (this.resolvedSpec?.securitySchemes) { const rapiDocApiKey = this.resolvedSpec.securitySchemes.find( (v: any) => v.securitySchemeId === rapidocApiKey, ); if (!rapiDocApiKey) { this.resolvedSpec.securitySchemes.push({ securitySchemeId: rapidocApiKey, description: "api-key provided in rapidoc element attributes", type: "apiKey", name: apiKeyName, in: apiKeyLocation, value: apiKeyValue, finalKeyValue: apiKeyValue, }); } else { rapiDocApiKey.name = apiKeyName; rapiDocApiKey.in = apiKeyLocation; rapiDocApiKey.value = apiKeyValue; rapiDocApiKey.finalKeyValue = apiKeyValue; } this.requestUpdate(); } } } super.attributeChangedCallback(name, oldVal, newVal); } onSpecUrlChange() { this.setAttribute("spec-url", (this.shadowRoot.getElementById("spec-url") as any).value); } /** * Programmatically loads a new OpenAPI specification. Accepts either a string URL or a valid * in-memory JSON/JavaScript spec object. The download and view buttons and the header's spec URL * box follow the spec loaded: its URL, or none for a spec object (the spec download buttons are * then hidden). * @public loadSpec(spec) */ async loadSpec(specUrl) { if (!specUrl) { return; } // The spec (URL or object) of the latest load: a filter-operations change re-filters this one this._lastLoadedSpec = specUrl; // Each load gets a token; a load whose token is no longer current never applies its result const token = ++this._specLoadSeq; try { this.resolvedSpec = { specLoadError: false, isSpecLoading: true, tags: [], }; this.loading = true; this.loadFailed = false; this.requestUpdate(); const spec = await ProcessSpec.call( this, specUrl, this.generateMissingTags === "true", this.sortTags === "true", this.sortSchemas === "true", this.getAttribute("sort-endpoints-by"), this.getAttribute("api-key-name"), this.getAttribute("api-key-location"), this.getAttribute("api-key-value"), this.getAttribute("server-url"), this.filterOperations, ); if (token !== this._specLoadSeq) { return; // a newer load started while this one was parsing } this.loading = false; this.afterSpecParsedAndValidated(spec, token); } catch (err: any) { if (token !== this._specLoadSeq) { return; } this.loading = false; this.loadFailed = true; this.resolvedSpec = null; console.error(`RapiDoc: Unable to resolve the API spec.. ${err.message}`); } } // A load queued for the end of the event loop, after the other attributes are set private _loadQueued = false; private _queuedSpec: { spec: any } | null = null; /** * Loads at the end of the event loop, once for any number of attribute changes in one go * (filter-operations and spec-url set together load the new spec, filtered, once): the spec a * spec-url change names, else the one loaded last. */ private queueLoad(next?: { spec: any }) { if (next) this._queuedSpec = next; if (this._loadQueued) return; this._loadQueued = true; window.setTimeout(async () => { this._loadQueued = false; const queued = this._queuedSpec; this._queuedSpec = null; await this.loadSpec(queued ? queued.spec : this._lastLoadedSpec || this.specUrl); }, 0); } /** * Programmatically supplies username and password credentials for an HTTP Basic security scheme * declared in the spec. * @public */ setHttpUserNameAndPassword(securitySchemeId, username, password) { return applyApiKey.call(this, securitySchemeId, username, password); } /** * Programmatically provides the token or key for a declared API Key, Bearer Token or OAuth * security scheme. Optional options.note says where the key * came from (for example the reader's sign-in); the Authentication section shows it in place of * that scheme's form, with a link to open the form. Changing or removing the key drops the note. * @public setApiKey(securitySchemeId, token, options) */ setApiKey(securitySchemeId, apiKeyValue, options: { note?: string } = {}) { return applyApiKey.call(this, securitySchemeId, "", "", apiKeyValue, options?.note || ""); } /** * Removes every API key, token and credential set on the element. * @public */ removeAllSecurityKeys() { return onClearAllApiKeys.call(this); } /** * Expands one operation and scrolls it into view. operation is * its operationId (getPetById) or its method and path (GET /pet/{petId}). Resolves to false when the element shows no such operation (not loaded yet, or left out by * filter-operations). * @public */ async showOperation(operation: string) { const text = String(operation || "").trim(); const [method, ...rest] = text.split(/\s+/); const path = rest.join(" "); const target = (this.resolvedSpec?.tags || []) .flatMap((t) => t.paths || []) .find((p) => path ? p.method === method.toLowerCase() && p.path === path : p.operationId === text, ); if (!target) return false; target.expanded = true; this.requestUpdate(); await this.updateComplete; const el = this.shadowRoot?.getElementById(target.elementId); el?.scrollIntoView({ behavior: "smooth", block: "nearest" }); return true; } /** * Programmatically switches the active target API server URL. * @public */ setApiServer(apiServerUrl) { return setApiServer.call(this, apiServerUrl); } async afterSpecParsedAndValidated(spec, token = this._specLoadSeq) { this.resolvedSpec = spec; // Once per load and before spec-loaded, so a key the page sets there (setApiKey) is not overwritten if (this.persistAuth === "true" && !spec.specLoadError) { recoverPersistedApiKeys.call(this); } this.selectedServer = undefined; if (this.defaultApiServerUrl) { if (this.defaultApiServerUrl === this.serverUrl) { this.selectedServer = { url: this.serverUrl, computedUrl: this.serverUrl, }; } else if (this.resolvedSpec.servers) { this.selectedServer = this.resolvedSpec.servers.find( (v: any) => v.url === this.defaultApiServerUrl, ); } } if (!this.selectedServer) { if (this.resolvedSpec.servers) { this.selectedServer = this.resolvedSpec.servers[0]; } } this.requestUpdate(); while (!(await this.updateComplete)); if (token !== this._specLoadSeq) { return; // a newer load took over while this one was rendering; it fires its own spec-loaded } const specLoadedEvent = new CustomEvent("spec-loaded", { detail: spec }); this.dispatchEvent(specLoadedEvent); if (this.mockServer === "true") { this.enableMock(); } } // Called by anchor tags created using markdown handleHref(e) { if (e.target.tagName.toLowerCase() === "a") { if (e.target.getAttribute("href").startsWith("#")) { const gotoEl = this.shadowRoot.getElementById( e.target.getAttribute("href").replace("#", ""), ); if (gotoEl) { gotoEl.scrollIntoView({ behavior: "auto", block: "start" }); } } } } }