Allow excluding individual methods from OpenApi output #1429
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
orpathsToMatch
configuration, but where a methodthat 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.