Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joatkh opened this issue Oct 24, 2024 · 2 comments
Open

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

joatkh opened this issue Oct 24, 2024 · 2 comments
Labels
p3 Type: Bug Something isn't working

Comments

@joatkh
Copy link

joatkh commented Oct 24, 2024

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

@joatkh joatkh added the Type: Bug Something isn't working label Oct 24, 2024
@tatomyr
Copy link
Contributor

tatomyr commented Oct 25, 2024

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.

@felipesanchezc88
Copy link

Thanks for reporting it, it took me a while to figure out what was happening. I will leave it like that and wait for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants