Index of every page on this site: llms.txt
All skills
gitbookio avatar

/write-openapi

@4c6497e
by GitBookgitbookio/gitbook-skills27 stars
7
Run it yourself

Author, configure, structure, and troubleshoot OpenAPI/Swagger API reference documentation in GitBook. Use this whenever a task involves a GitBook OpenAPI block or `{% openapi %}` block, adding or updating an OpenAPI/Swagger spec in GitBook (by file or URL, via the API, MCP, CLI, or app UI), generating API reference pages from a spec, configuring the interactive "Test it" runner (auth, servers, CORS, proxy), customizing pages with GitBook `x-*` extensions (icons, titles, navigation hierarchy, code samples, enum descriptions), marking operations experimental/deprecated/hidden, or automating spec updates in CI/CD. Trigger even when the user only mentions GitBook plus OpenAPI, puts an `x-` extension on a spec destined for GitBook, or asks "why isn't my spec loading" or "why doesn't Test it work", without naming this skill.

Use this Skill: https://skilld.dev/gh/gitbookio/gitbook-skills/write-openapi

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestest-it-setup.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Configuring the "Test it" runner

The interactive runner (powered by Scalar) lets readers send real requests from the page. It can only do what the spec describes: it targets the URLs in servers and only offers the auth declared under components.securitySchemes. This file covers how to wire those together, plus CORS and the proxy.

Contents

  • Declare an auth scheme (Bearer/JWT, API key, OAuth2)
  • Apply schemes globally or per operation
  • Customize the auth prefix and token placeholder
  • Control the endpoint URL with servers
  • CORS: the usual reason requests fail
  • Route requests through the proxy
  • Hide the runner

Declare an auth scheme

The runner can only present and apply auth if the spec declares it. Define schemes under components.securitySchemes. Use straight quotes in YAML.

HTTP Bearer (e.g. JWT):

openapi: '3.0.3'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

API key in a header:

components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

OAuth2 (authorization code flow):

components:
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: 'https://auth.example.com/oauth/authorize'
          tokenUrl: 'https://auth.example.com/oauth/token'
          scopes:
            read:items: 'Read items'
            write:items: 'Write items'

Apply schemes globally or per operation

A top-level security applies to every operation; a security on an operation overrides the global value for that endpoint.

Global:

openapi: '3.0.3'
security:
  - bearerAuth: []
paths: ...

Per operation:

paths:
  /reports:
    get:
      summary: Get reports
      security:
        - apiKeyAuth: []
      responses:
        '200':
          description: OK

Customize the auth prefix and token placeholder

Adjust how a security scheme renders in the runner:

  • x-gitbook-prefix sets the prefix before the token, giving Authorization: <prefix> YOUR_API_TOKEN. It is not supported on http schemes, which must follow standard IANA authentication definitions.
  • x-gitbook-token-placeholder sets the default token value shown to the reader.
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: Authorization
      x-gitbook-prefix: Token
      x-gitbook-token-placeholder: YOUR_CUSTOM_TOKEN

Control the endpoint URL with servers

The runner sends requests to the URL(s) in servers. Declare one or more, and parameterize with variables if needed.

Single server:

servers:
  - url: https://instance.api.region.example.cloud

Multiple servers (reader picks one):

servers:
  - url: https://api.example.com
    description: Production
  - url: https://staging-api.example.com
    description: Staging

Server variables:

servers:
  - url: https://{instance}.api.{region}.example.cloud
    variables:
      instance:
        default: acme
        description: Your tenant or instance slug
      region:
        default: eu
        enum: [eu, us, ap]
        description: Regional deployment

Per-operation server:

paths:
  /reports:
    get:
      summary: Get reports
      servers:
        - url: https://reports.api.example.com
      responses:
        '200':
          description: OK

CORS: the usual reason requests fail

Browsers block cross-origin requests unless the API opts in. By default the runner sends requests from the reader's browser, so a spec added by URL needs the API to allow cross-origin GET requests from the docs origin (for example https://your-site.gitbook.io or a custom domain). A public, credential-free endpoint can return Access-Control-Allow-Origin: *.

If the API cannot send the right CORS headers, use the proxy instead.

Route requests through the proxy

GitBook can proxy requests server-side so they work even without CORS. Enable with x-enable-proxy.

Whole spec:

openapi: '3.0.3'
x-enable-proxy: true
info:
  title: Example API
  version: '1.0.0'
servers:
  - url: https://api.example.com

Per operation (operation value takes precedence over the root):

paths:
  /reports:
    get:
      summary: List reports
      x-enable-proxy: true
      responses:
        '200': { description: OK }
    post:
      summary: Create report
      x-enable-proxy: false
      responses:
        '201': { description: Created }

What it supports and its limits:

  • Forwards all HTTP methods (GET, POST, PUT, DELETE, PATCH), headers, cookies, and request bodies.
  • Only forwards to URLs listed in the spec's servers array; it cannot reach arbitrary URLs. List every base URL you want to test, or requests to an unlisted host bypass the proxy.

Hide the runner

Remove the "Test it" panel from an endpoint, or from the whole spec by placing it at the root.

paths:
  /example:
    get:
      operationId: examplePath
      x-hideTryItPanel: true

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alertstoday3 checks · Risk SAFE
  • Gen Agent Trust Hub4d

    This skill provides instructions for authoring, configuring, and publishing OpenAPI/Swagger documentation to GitBook using the GitBook API, CLI, or MCP. It includes best practices for security, specifically regarding the handling of API tokens.

  • Sockettoday

    No alerts

  • Snyk4d

    Risk: LOW · No issues

Signed by skilld at 4c6497e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated 5 days ago
metadata
{
  "version": "1.0"
}

README badge

README badge for gitbookio/gitbook-skills/write-openapi