Skip to content

Allow excluding individual methods from OpenApi output #1429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2022

Conversation

mc1arke
Copy link
Contributor

@mc1arke mc1arke commented Jan 7, 2022

It is currently possible to prevent methods from being included in the
OpenAPI output by ensuring the parent class is not covered by the
packagesToScan or pathsToMatch configuration, but where a method
that a user doesn't want included in the output is present in a class
that is included in the configuration, and that method shares a path
with other endpoints that also require inclusion, there's no way for a
user to exclude the method from being exposed as an operation in the
OpenAPI output.

To overcome this limitation, a MethodFilter has been introduced which
allows for a user to selectively exclude individual methods from being
parsed for their definitions. Every method that's detected for
potential inclusion in the OpenApi output is passed to the filter, and
any method that the filter rejects is excluded from further processing.
As multiple filters can be applied in a single configuration, the
result of all the filters is combined in an 'and' result, so all
filters must accept a method the have it available in the output.

This functionality allows for the annotation filtering feature in
SpringFox to be re-implemented by users, by creating a method filter
similar to method -> method.isAnnotationPresent(MyAnnotation.class),
although allows much finer control since any other reflective
attributes of the method can also be checked at the same time.

It is currently possible to prevent methods from being included in the
OpenAPI output by ensuring the parent class is not covered by the
`packagesToScan` or `pathsToMatch` configuration, but where a method
that a user doesn't want included in the output is present in a class
that is included in the configuration, and that method shares a path
with other endpoints that also require inclusion, there's no way for a
user to exclude the method from being exposed as an operation in the
OpenAPI output.

To overcome this limitation, a MethodFilter has been introduced which
allows for a user to selectively exclude individual methods from being
parsed for their definitions. Every method that's detected for
potential inclusion in the OpenApi output is passed to the filter, and
any method that the filter rejects is excluded from further processing.
As multiple filters can be applied in a single configuration, the
result of all the filters is combined in an 'and' result, so all
filters must accept a method the have it available in the output.

This functionality allows for the annotation filtering feature in
SpringFox to be re-implemented by users, by creating a method filter
similar to `method -> method.isAnnotationPresent(MyAnnotation.class)`,
although allows much finer control since any other reflective
attributes of the method can also be checked at the same time.
@bnasslahsen bnasslahsen merged commit 6361201 into springdoc:master Jan 8, 2022
@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Jan 8, 2022

Thank you @mc1arke for your contribution to the project.

I have made little adjustments so the feature can also be available without using groups.
I have also renamed the interface MethodFilter to OpenApiMethodFilter.

As this feature will be available only programmatically (without using properties), i had to remove some code from SpringDocConfigProperties.

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