thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
https://openapi-format-playground.vercel.app
MIT License
98 stars 15 forks source link

When filtering unused schemas, schemas that are only self-referenced still show up #147

Open aneeshnazar opened 3 days ago

aneeshnazar commented 3 days ago

We're trying to use this filterFile:

{
  "methods": [],
  "inverseMethods": [],
  "tags": [],
  "inverseTags": [],
  "operationIds": [],
  "inverseOperationIds": [],
  "operations": [],
  "flags": [],
  "inverseFlags": [],
  "flagValues": [],
  "inverseFlagValues": [],
  "unusedComponents": [
    "schemas"
  ],
  "stripFlags": [],
  "responseContent": [],
  "inverseResponseContent": [],
  "requestContent": [],
  "inverseRequestContent": []
}

to filter our OpenAPI specs. It works for most use-cases, but schemas like this, that are not being referenced elsewhere in the filtered spec:

components:
  schemas:
    selfRefSchema:
      type: object
      properties:
        children:
          type: array
          items:
            $ref: "#/components/schemas/selfRefSchema"

are also being captured

thim81 commented 2 days ago

hi @aneeshnazar

I recreated your example in the playground

If I understand correctly, you also want to remove schema that are only referencing themselves? If they would be used somewhere else they would have to remain?

I'm bit surprised how a schema would reference itself, can you share that case so we can look into building the logic to filter out this case.