Loading Your Spec
Supported versions
Section titled “Supported versions”| Version | Support |
|---|---|
| OpenAPI 3.1 and 3.2 | Read as they are, including JSON Schema 2020-12 and webhooks. |
| OpenAPI 3.0 | Read as it is. |
| Swagger 2.0 | Upgraded to OpenAPI 3.1 in the browser before rendering. For large specs, convert ahead of time (see Large Specs). |
Specs can be JSON or YAML. RapiDoc resolves $refs, including references to other files relative to the spec’s URL, but does not validate the spec: use rapidoc validate for that.
Three ways to load a spec
Section titled “Three ways to load a spec”From a URL
Section titled “From a URL”<rapi-doc spec-url="https://api.example.com/v1/openapi.yaml"></rapi-doc>Changing spec-url later loads the new spec.
Specs on another domain
The browser fetches the spec, so a spec on a different domain or port than the page must be served with CORS headers, at least:
Access-Control-Allow-Origin: *If you can’t change that server, serve a copy of the spec from your own site, or fetch it yourself and use loadSpec.
From JavaScript
Section titled “From JavaScript”loadSpec() takes a spec object or a URL. Use it when you fetch the spec yourself, for example with the user’s credentials:
const doc = document.querySelector('rapi-doc');
const res = await fetch('/internal/openapi.json', { headers: { Authorization: `Bearer ${sessionToken}` },});doc.loadSpec(await res.json());Inside the element
Section titled “Inside the element”Put the spec as JSON in a <script> inside <rapi-doc>, with slot="rapidoc-spec". It is read once, when the element is added to the page, and takes precedence over spec-url.
<rapi-doc> <script type="application/json" slot="rapidoc-spec"> { "openapi": "3.1.0", "info": { "title": "Embedded API", "version": "1.0.0" }, "paths": {} } </script></rapi-doc>How OpenAPI features are shown
Section titled “How OpenAPI features are shown”oneOfandanyOf: the variants are listed as numbered options (OPT 1, OPT 2, …) under a ONE OF or ANY OF label.allOfis merged into one schema.- Several examples: when a media type has an
examplesmap, a picker switches between them. - Servers and server variables: the API Servers section lists the spec’s
servers; readers pick one, and fill in its variables (such as{environment}), before pressing Try.