Skip to content

feat(filter-in): add applyTo option to limit filtering to specific node types#2536

Open
balvig wants to merge 1 commit intoRedocly:mainfrom
balvig:fix/filter-in-tags-property
Open

feat(filter-in): add applyTo option to limit filtering to specific node types#2536
balvig wants to merge 1 commit intoRedocly:mainfrom
balvig:fix/filter-in-tags-property

Conversation

@balvig
Copy link

@balvig balvig commented Feb 4, 2026

What/Why/How?

When using filter-in with property: tags to filter operations by tag, the decorator filters any schema properties that happen to be named "tags", which can case undesirable results in cases such as this:

# configuration
filter-in:
  property: tags
  value: App

# schema
openapi: 3.0.0
paths:
  /events:
    get:
      tags:
        - App
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Event'
components:
  schemas:
    Event:
      type: object
      properties:
        id:
          type: string
        tags:  # <-- This property gets incorrectly filtered out!
          type: array
          items:
            type: string
          description: User-defined tags for the event

This PR adds an applyTo option that lets users specify which node type the filter applies to (e.g., PathItem).
This prevents unintended filtering of schema properties while still allowing filtering at the operation level:

filter-in:
  property: tags
  value: App
  applyTo: PathItem

Testing

Added a test case that verifies:

  • Operations with the correct tag are included
  • Operations with wrong tags are filtered out
  • Schema properties named "tags" are preserved (not filtered)

Check yourself

  • Have you added a changeset for your changes?
  • Have you added tests?

…de types

The `filter-in` decorator uses an `any` visitor which visits all nodes
in the OpenAPI document. When filtering by a property like `tags`, this
can incorrectly match schema property definitions that happen to have
the same name.

For example, a schema with a `tags` property:
```yaml
components:
  schemas:
    Event:
      properties:
        tags:
          type: array
          items:
            type: string
```

When using `filter-in` with `property: tags` and `value: App`, the
schema property definition would be filtered out because it has a
`tags` property that doesn't match "App".

This adds an `applyTo` option that allows users to specify which node
type the filter should apply to. For example, `applyTo: PathItem` will
only filter PathItem nodes, avoiding the schema property issue:

```yaml
decorators:
  filter-in:
    property: tags
    value: App
    applyTo: PathItem
```

The default behavior (without `applyTo`) remains unchanged for backward
compatibility.
@changeset-bot
Copy link

changeset-bot bot commented Feb 4, 2026

🦋 Changeset detected

Latest commit: a568cdc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Minor
@redocly/cli Minor
@redocly/respect-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@balvig balvig marked this pull request as ready for review February 4, 2026 04:50
@balvig balvig requested review from a team as code owners February 4, 2026 04:51
@tatomyr
Copy link
Collaborator

tatomyr commented Feb 5, 2026

This is a good contribution, @balvig, thank you!

However, I'd like to point to a couple of things here.
First, if adding applyTo to filter-in, it's worth adding it to filter-out as well (and reflect that in the corresponding docs).
Second, it looks odd that we have to specify PathItem when we're actually targeting the Operation level.

Currently I'm trying to revise the logic at all in scope of this ticket. I'm leaning towards creating a separate decorator (something like filter-in-operations) that will target specifically operations as those are the atomic values of OpenAPI. I might end up introducing the applyTo configuration property there too though.

What do you think? Wouldn't that new decorator serve your purpose better?

@balvig
Copy link
Author

balvig commented Feb 6, 2026

Wouldn't that new decorator serve your purpose better?

@tatomyr it probably would!

All I really need is a way to filter in/out operations based on tags, without affecting other nodes that happen to have a tags property. 🙂

@tatomyr
Copy link
Collaborator

tatomyr commented Feb 6, 2026

@balvig I'll try to file a draft PR later today or early next week.

@tatomyr
Copy link
Collaborator

tatomyr commented Feb 11, 2026

@balvig could you check if the tests are covering your case? #2555

@balvig
Copy link
Author

balvig commented Feb 12, 2026

Thank you @tatomyr, I think so!

The particular issue I had was with a child element also containing a tags property and getting unintentionally removed, so not sure if worth covering that edge case in the tests, but otherwise looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants