Skip to content

OpenAPI external $ref not resolved when using shared components file #4139

@diecaosrixsus

Description

@diecaosrixsus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions