openapi-format icon indicating copy to clipboard operation
openapi-format copied to clipboard

inverseFlags/inverseFlagValues do not keep referenced schemas

Open tomasbreffitt opened this issue 10 months ago • 2 comments

Version 1.25.0 Hello, I am recreating #152 as it turns out it is not an issue with multiple files, but even within 1 file. I was able to simplify the schema down to the bare minimum.

I've uploaded my examples to a git repo: https://github.com/tomasbreffitt/openapi-format-examples/tree/main

In each directory, inverseFlags and inverseFlagValues, I ran the following commands, output is included in my repo.

openapi-format oas.yaml -o output/filtered.yaml -f filter.yaml
openapi-format oas.yaml -o output/unfiltered.yaml 

In my repo, you can see that in both cases, the filtered version does not keep the components.

As in my previous issue, I used both x-public: true in the inverseFlags and x-visibility: true in the inverseFlagValues commands.

I pasted both oas.yaml files to https://editor-next.swagger.io/ to test validity. I also ran them through rdme's validator as a sanity check and they passed.

As before, I am happy to assist in anyway, despite my lacking JS skills and I really appreciate the work on this tool, regardless, it still brings lots of value to me.

tomasbreffitt avatar Jan 28 '25 19:01 tomasbreffitt

hih @tomasbreffitt

Thanks for taking the time to create the reproduce cases. I'll use that verify which logic gets triggered and what could be the cause of the reported behaviour.

I'll keep you posted when I have found the time to run some experiments.

thim81 avatar Jan 31 '25 16:01 thim81

I noticed you added the playground, so I've added my examples there:

tomasbreffitt avatar Apr 24 '25 17:04 tomasbreffitt

hi @tomasbreffitt

Great that you shared your examples, I'll use to debug the reported case. It looks that the inverseFlag methods are being very ruthless when it comes to filtering out.

I'll have to find a way to make it keep referenced components.

thim81 avatar Apr 25 '25 08:04 thim81

hi @tomasbreffitt

I just released openapi-format v1.26.0 which includes the changes to makes the inverseFlag & inverseFlagValues less aggressive.

The inverse filtering keeps only the path operations, tags, x-tagGroups that match the filter rule. This was a very aggressive option to keep only the items that are needed, but now it will keep the components. The components can best be filtered out, by using the inverse filters in combination with the "unusedComponents" filter option.

BEFORE:

Image

AFTER

Image

BEFORE

Image

AFTER

Image

thim81 avatar May 02 '25 09:05 thim81

@tomasbreffitt

You can validate your playground, which now should behave as you expect:

If it works as expected, feel free to close this issue. If not report back, so we can continue our investigation.

thim81 avatar May 02 '25 09:05 thim81

@thim81 awesome! This seems to work perfectly. It does not strip unused schemas by default, but the unusedComponents filter works perfectly for that

tomasbreffitt avatar May 06 '25 19:05 tomasbreffitt