thim81 / openapi-format

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

Inverse flags #79

Closed sekaranglila closed 1 month ago

sekaranglila commented 11 months ago

Hi, I was wondering if we can implement inverse flags as well? Thank you

thim81 commented 11 months ago

hi @sekaranglila

I would have to investigate if it is possible.

thim81 commented 10 months ago

hi @sekaranglila

could you share an example of what would be the input and expected output?

sekaranglila commented 6 months ago

Hi @thim81 , sorry for the late reply. For example, I'd like to keep certain objects that aren't used in the remaining APIs (e.g. Callback Objects). However, there's no way to persist them without inverse flags. I could keep them if I could add flags like x-callback-object: false to all the other objects, but in a large file that would be too much toil, so instead an inverse flag is much more preffered.

stvnwrgs commented 2 months ago

@thim81 We have the same need, inverseFlagValue would be even more helpful.

We have the following use case:

We want to split our big API file into smaller API specs based on different API use cases. So we've added

paths:
  /api/resource/subscription:
    get:
      parameters: []
      responses:
        '200':
          description: asd
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Example'
      deprecated: false
      tags:
        - Actor
      x-custom-api-name: payment-api

  /api/resource/user:
    get:
      parameters: []
      responses:
        '200':
          description: asd
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Example'
      deprecated: false
      tags:
        - Actor
      x-custom-api-name: management-api

We want to filter the paths based on the x-custom-api-name and keep the references that are linked inside the paths.

thim81 commented 2 months ago

@stvnwrgs to double-check, you want to keep all the flags with a value that match

Example:

inverseFlagValues:
    - x-custom-api-name: management-api

Should keep only the management-api flagged items like the /api/resource/user operation?

thim81 commented 2 months ago

@stvnwrgs @sekaranglila

I just created a PR to introduce the inverseFlagValue option. It is a very aggresive filter, since it will only keep the elements where the flag with the value is present.

For now, it focusses on inverse filtering for flagValues for operations, components, tags, x-tagGroups. The elements like info, servers remain untouched by the inverseFlagValue filtering.

thim81 commented 2 months ago

The PR will bring the support for inverseFlags and inverseFlagValues option.

thim81 commented 2 months ago

@stvnwrgs @sekaranglila

If you have 5 min could review the provided examples (input->output) are behaving as expected for the inverseFlags & inverseFlagValues.

https://github.com/thim81/openapi-format/tree/79-inverse-flagvalues/test/yaml-filter-inverse-flags https://github.com/thim81/openapi-format/tree/79-inverse-flagvalues/test/yaml-filter-inverse-flags-flagsValues

It removes all items in operations, components, tags, x-tagGroups that don't have the flags present.

thim81 commented 1 month ago

hi @stvnwrgs and @sekaranglila

Could you have a look at the PR with the inverseFlags & inverseFlagValues.

https://github.com/thim81/openapi-format/tree/79-inverse-flagvalues/test/yaml-filter-inverse-flags https://github.com/thim81/openapi-format/tree/79-inverse-flagvalues/test/yaml-filter-inverse-flags-flagsValues

Would this solve your use-cases?

stvnwrgs commented 1 month ago

Hey @thim81, yes this is exactly what I would need. Thank you for the quick implementation!

thim81 commented 1 month ago

hi @stvnwrgs and @sekaranglila

openapi-format 1.17.0 is just released, which includes the new features for inverse flag & flagValues filtering