GitbookIO / GitbookIO/gitbook

OpenAPI external $ref not resolved when using shared components file

Open
#4,139 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
29k
Forks
4k
Avg merge
1d 2h
Merged PRs (30d)
71

Description

Bug description

GitBook does not resolve external $ref references when using OpenAPI specifications with shared component files.

We are trying to maintain a centralized file containing reusable error responses for our API, but when referencing the file using a relative $ref, GitBook fails to render the response in the documentation.

Example:

"500": {
  "$ref": "../error-responses.json#/components/responses/InternalServerErrorResponse"
}

The referenced file exists, the path is correct, and the same structure works correctly in Swagger / OpenAPI tools, but GitBook does not resolve the reference and the response is missing from the rendered documentation.

Expected behavior:

GitBook should support external $ref references in OpenAPI files, allowing reusable components across multiple files, as defined in the OpenAPI specification.

Actual behavior:

External $ref references are ignored and the response schema is not rendered.

This makes it difficult to keep API error definitions centralized and forces duplication across specs.

How to reproduce

  1. Create an OpenAPI spec inside GitBook
  2. Create a separate JSON file with shared responses
  3. Reference the response using $ref with a relative path
  4. Open the API documentation page in GitBook
  5. The response is not rendered

Additional context

Example folder structure:

openapi/
  specs/
       spec.json
  error-responses.json

Example error-responses.json:

{
  "components": {
    "responses": {
      "InternalServerErrorResponse": {
        "description": "Internal server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}

OpenAPI version: 3.x
GitBook version: (please fill)

If external references are not supported, please confirm the recommended way to share common components across multiple OpenAPI specs in GitBook.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using openapi/specs/spec.json and openapi/error-responses.json with the relative external $ref shown in the report. Start by tracing how the OpenAPI 3.x documentation page loads and resolves that reference; done means the shared InternalServerErrorResponse renders, or the supported limitation and recommended sharing method are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.