thim81 / openapi-format

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

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

Open aneeshnazar opened 1 month ago

aneeshnazar commented 1 month 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 1 month 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.

thim81 commented 12 hours ago

hi @aneeshnazar

Did you have some time to look at my questions? So we can further look into this.