Skip to content

Bundler breaks external schemas with self-references #508

@califlower

Description

@califlower

Problem

When bundling OpenAPI specs, external schemas that contain self-references get inlined, but their internal $ref pointers remain unchanged, creating dangling references that cause composition to fail.

Example

main.yaml:

openapi: 3.1.0
paths:
  /tree:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: './external.yaml#/components/schemas/Tree'

external.yaml:

components:
  schemas:
    Tree:
      type: object
      properties:
        name:
          type: string
        children:
          type: array
          items:
            $ref: '#/components/schemas/Tree'  # Self-reference

Expected Behavior

The Tree schema should be copied to the root document's components with the self-reference remaining valid (or it should do what was done before, and should be left alone):

components:
  schemas:
    Tree:
      type: object
      properties:
        name:
          type: string
        children:
          type: array
          items:
            $ref: '#/components/schemas/Tree'  # Still valid

Actual Behavior

The Tree schema body is inlined directly into the response, but the self-reference still points to #/components/schemas/Tree, which doesn't exist in the root document:

paths:
  /tree:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                  children:
                    type: array
                    items:
                      $ref: '#/components/schemas/Tree' 

Calling BundleBytesComposed() fails with:

component `#/components/schemas/Tree` does not exist in the specification

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions