Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
944 stars 149 forks source link

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

Open joatkh opened 3 weeks ago

joatkh commented 3 weeks ago

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


2. 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" } } } }

3. 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:

OpenAPI description

Using version 3.1

Redocly Version(s)

1.25.8

Node.js Version(s)

22.4.0

OS, environment

MacOS Sonoma + Ubuntu

tatomyr commented 3 weeks ago

I confirm this is a bug. Thanks for reporting it! Interesting enough, if you replace the current ref pointer with "#/components/schemas/iwillbedrop", both components will be removed.