Document an API
Show the operations of an OpenAPI spec in your pages, and let readers try them.
The OpenAPI reference block renders operations from an OpenAPI 3.0 or 3.1 specification: parameters, request bodies, responses, schemas and authentication, with code samples.
Add a spec#
Type
/openapiand choose OpenAPI reference.Paste the spec's URL, or upload the file (JSON or YAML).
Choose what to show: the whole spec, every operation of one path, or a single operation.
Split a large API across pages — one page per resource, each block showing that resource's paths — so the table of contents mirrors your API.
{% openapi src="https://api.example.com/openapi.json" path="/pets/{petId}" method="get" %}
[openapi.json](https://api.example.com/openapi.json)
{% endopenapi %}GitBook's older {% swagger %} tag is read too.
Keep it current#
Docsheaf reads the spec in the background, caches it, and reads it again about every six hours and whenever a page with a new spec is saved. Published pages always render from the cache, so a slow or unreachable API server never slows your docs down.
Specs must be reachable on a public address and be at most 5 MB. $refs inside the file are
resolved. Swagger 2.0 isn't supported — convert it to OpenAPI 3 first.
Let readers try requests#
Turn on Let readers try API requests (under API playground in the site's Customize page) to add Try it to every operation. Readers fill in parameters and credentials and send the request from their browser, straight to your API.
Docsheaf never relays the request — there is no proxy — so your API must allow the docs site's origin through CORS. If a request fails without a response, the playground explains which
Access-Control-Allow-Originto add and offers Copy as cURL.Credentials stay in the reader's open tab. They are never stored, logged or sent anywhere but the request.
Anything other than GET, HEAD or OPTIONS asks the reader to confirm first.
Insert an API reference with code#
Want a page per operation, generated from your spec in CI? Write the pages as Markdown with
{% openapi %} tags and push them with Git Sync.
Was this helpful?
Last updated
View as Markdown