Skip to content

remove-unused-components doesn't remove recursive schemas #1783

Open
@joatkh

Description

Describe the bug

Using remove-unused-components decorator leave some schemas unused by operations but that are recursive.

To Reproduce
Steps to reproduce the behavior:

  1. Given this redocly.yaml file
decorators:
  remove-unused-components:
    type: remove-unused-components
    
apis:
  test:
    root: test.json
  1. And this OpenAPI file(s)
{
    "openapi": "3.1.0",
    "components": {
      "schemas": {
        "iwontbedrop": {
          "properties": {
            "Myprop": {
              "items": {
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/iwontbedrop"
                  }
                ]
              },
              "type": "array"
            }
          },
          "type": "object"
        },
        "iwillbedrop": {
          "properties": {
            "name": {
              "title": "Name",
              "type": "string"
            }
          },
          "type": "object"
        }
     }
  }
}
  1. Run this command redocly bundle

Expected behavior

The schema iwontbedrop being recursive is not drop even if not used outside of it's scope. So the expectation would be to have both iwontbedrop and iwillbedrop to be dropped

Logs

bundling .../test.json...
openapi: 3.1.0
components:
  schemas:
    iwontbedrop:
      properties:
        Myprop:
          items:
            anyOf:
              - $ref: '#/components/schemas/iwontbedrop'
          type: array
      type: object
📦 Created a bundle for .../test.json at stdout 13ms.
🧹 Removed 1 unused components.

OpenAPI description

Using version 3.1

Redocly Version(s)

1.25.8

Node.js Version(s)

22.4.0

OS, environment

MacOS Sonoma + Ubuntu

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't workingp3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions