Methods
Called on the element, for example document.querySelector('rapi-doc'). How to use them is in Control It from JavaScript.
const doc = document.querySelector('rapi-doc');
await doc.loadSpec('https://rapidocui.com/specs/petstore.yaml');doc.setApiServer('https://petstore3.swagger.io/api/v3');doc.setApiKey('api_key', 'demo-key');doc.scrollToPath('get-/pet/{petId}');Nothing on this page matches.
| Method | Description |
|---|---|
loadSpec(spec) | 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). See it running → |
bindNavBar(sidebar, options) | Connects a sidebar rendered outside the component (for example the static HTML from getNavBarHtml in @rapidoc/prerender) to this element: clicks navigate with scrollToPath, the active item follows nav-active-change, and the filter box filters the sidebar. sidebar is an element or a CSS selector; options accepts activeClass (default active) and updateHistory
(default true). Returns a function that removes the
bindings. |
scrollToPath(path) | Programmatically scrolls the viewport to focus on a specific endpoint section. The path argument is the operation's element ID (e.g., login-user) or its method + path anchor (e.g., get-user-login; the older get-/user/login
format also works). See it running → |
setHttpUserNameAndPassword(securitySchemeId, username, password) | Programmatically supplies username and password credentials for an HTTP Basic security scheme
declared in the spec. |
setApiKey(securitySchemeId, token, options) | 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. |
setApiServer(apiServerUrl) | Programmatically switches the active target API server URL. |
generateMcpServer(options) | Builds the MCP manifest and the exported project in memory. Returns { manifest, files, budget, hostConfig }: manifest is the plain JSON description of the server (one tool per operation
with a JSON Schema inputSchema, MCP annotations and the operation the runtime
executes), files maps every file of the zip to its text
(manifest.json, server.ts, runtime.js, package.json, README.md, mcp.json), budget is the
token diagnostics and hostConfig the text of
mcp.json, the entry for an AI app's MCP configuration. options: serverName, includeInternal, includeDeprecated, includeOperations (false: only the workflow
tools of a paired <rapi-flow>). |
downloadMcpServer(options) | Downloads the exported project as <server-name>-mcp.zip (<server-name>-workflows-mcp.zip with includeOperations: false). Same options
as generateMcpServer. |
getMcpBudget(options) | Returns prompt token overhead diagnostics for the current OpenAPI specification: { totalTools, totalResources, estimatedTokens, consequentialCount,
warnings }, where consequentialCount is the number of
tools that are not read-only and warnings lists context
footprint warnings (over 30 tools or 5,000 tokens). |