Skip to content

Negative matching nor predicate support in ConditionalInterceptor.Subject #14

@MathieuTricoire

Description

@MathieuTricoire

Is your feature request related to a problem? Please describe it.

When using ConditionalInterceptor.Subject it's currently only possible to target .all, .services, or .methods.
This makes it difficult to express common cases like "apply this interceptor to all methods except a small set" without manually listing every included method or service. For example applying authentication everywhere except health check and authentication services.

Describe the solution you'd like

  1. Negative variants
    Add negative forms alongside the existing .services / .methods, for example:

    .exceptServices(Set<ServiceDescriptor>)
    .exceptMethods(Set<MethodDescriptor>)

    This would keep the current per-scope structure but add the ability to exclude instead of include.

  2. Unified include/exclude
    Alternatively or additionally, introduce single cases that accept both services and methods at once:

    .only(services: Set<ServiceDescriptor> = [], methods: Set<MethodDescriptor> = [])
    .except(services: Set<ServiceDescriptor> = [], methods: Set<MethodDescriptor> = [])

    This keeps the API minimal, avoids combining multiple subjects, and makes it easy to mix service-level and method-level rules.

  3. Predicate-based matching
    Additionally add a form such as:

    .predicate(@Sendable (MethodDescriptor) -> Bool)

    The library already caches interceptor lists per method (for what I understand), so the predicate should be pure/static (same result for a given method, not dependent on runtime state).

    This would fill the gap for complex inclusion/exclusion logic and avoid introducing heavier mechanisms like arrays of subjects with combination rules.

    If you already have ideas or internal discussions about expanding Subject matching in a different way, I'd be interested to hear your thoughts.

Describe alternatives you've considered

Manually enumerating all "included" services or methods except the few to be excluded. This works but it's error-prone and hard to maintain, especially when new services or methods are added.

Additional context

I'd be happy to open a PR for this once we agree on the desired semantics and API shape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementImprovements to existing feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions