thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
77 stars 14 forks source link

filtering unused components - not working #107

Open connorsadler opened 2 weeks ago

connorsadler commented 2 weeks ago

Hi,

I am trying to filter a yaml openapi spec, to remove a path and remove unused schema components. The path filtering works fine, but the unused component removal does not work - unless I deliberately add an unused component to the original file (I did this by accident while experimenting)

Please see attached zip file for sample files and README.md with steps to reproduce issue I will also copy in README.md below

There is always the possibility that I am doing something wrong - apologies if that is the case here.

Thanks,

Connor

Mac OS openapi-format version: tried with 1.14.0 and 1.17.0 - same results

PROBLEM: The 'remove unused components' doesn't work - it leaves some items in there that it shouldn't

Steps to show problem:

  1. edit spec: pet-sample-openapi-spec.yaml observe it has 2 paths, each path references a response schema object which uses a second schema object
  2. filter the spec by running: ./dev-produce-filtered-spec.sh this uses "dev-produce-filtered-spec_customFilter.yaml" which only includes one of the paths (WORKS) but should removed unused "schemas" (DOESNT WORK)
  3. edit result: pet-sample-openapi-spec_filtered.yaml observe it includes only one path (correct), but all the schema objects are included - some of which are unused so should have been removed
  4. edit spec 2: pet-sample-openapi-spec-2.yaml observe it is the same as the first spec, but it has an unused component in schemas: ThisTypeIsNeverReferencedAnywhere
  5. filter the spec 2 by running: ./dev-produce-filtered-spec-2.sh Note: In the output it says it's removed some unused components
  6. edit result: pet-sample-openapi-spec_filtered-2.yaml observe the filtering has now worked - one path and all unused components have been removed

Archive.zip

thim81 commented 1 week ago

hi @connorsadler

Thanks for providing the detailed reproduction steps.

When I find some time, I'll try to reproduce the behavior based on your archive.zip and steps.

I'll share update once we have them.

connorsadler commented 1 week ago

Thanks We can work around it for the moment by just including a dummy unused item in the original spec, which we are in control of