Redocly / Redocly/redocly-cli

Bundling Creates Redundant Schema Objects for `$defs`

Open
#963 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3 Type: Bug
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

Describe the bug
Bundling a multi-file OpenAPI spec using $defs creates redundant schema objects in the bundled file.

To Reproduce

  1. Create a multi-file OpenAPI spec that contains a schema object with $defs:

main.yaml

openapi: 3.1.0

info:
  title: API
  version: v1

servers:
  - url: https://domain.com

components: {}

paths:
  /test:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: './schemas.yaml#/MyObject'

schemas.yaml

MyObject:
  type: object
  properties:
    key:
      $ref: '#/MyObject/$defs/anotherObject'
  $defs:
    anotherObject:
      type: object
      properties:
        anotherKey:
          type: string

.redocly.yaml

apis:
  example:
    root: main.yaml
  1. run openapi bundle example -o bundled.yaml

See that the bundled file has a redundant anotherObject schema that is being used in place of MyObject/$defs/anotherObject

bundled.yaml

openapi: 3.1.0
info:
  title: API
  version: v1
servers:
  - url: https://domain.com
components:
  schemas:
    anotherObject:
      type: object
      properties:
        anotherKey:
          type: string
    MyObject:
      type: object
      properties:
        key:
          $ref: '#/components/schemas/anotherObject'
      $defs:
        anotherObject:
          type: object
          properties:
            anotherKey:
              type: string
paths:
  /test:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MyObject'

Expected behavior
The bundled file should use the existing definition instead of creating a duplicate schema object.

Redocly Version(s)
1.0.0-beta.113

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

Start by reproducing the issue with main.yaml, schemas.yaml, and .redocly.yaml, then run openapi bundle example -o bundled.yaml and compare the generated schemas with the expected structure. Trace the bundling path that handles $defs; done means the bundle reuses MyObject/$defs/anotherObject instead of creating a duplicate top-level schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.