Skip to content
New issue

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

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

Already on GitHub? # to your account

Make scanning all JAX-RS packages explicit #3283

Closed

Conversation

reta
Copy link
Contributor

@reta reta commented Sep 4, 2019

Description

The regression [1] has been reported by one of the CXF users with respect to Swagger Core releases after 2.0.6 , here is the issue.

The JAX-RS service has instance of the Application class which has only one resource class returned by getClasses() method. The service uses Swagger 2.0.8 + OpenAPI v3 and does not specify any resources classes and resource packages to scan (assuming those will be taken from the Application instance). Before 2.0.7 it was the case but since than the Swagger Core changed implementation from Reflections to ClassGraph, and now always scan the complete class path if resource classes and resource packages are empty. The classes from the Application instance are added on top and there is no way to tailor this behavior.

There are couple of solutions to make the behavior more controllable. The one presented in this PR is very simple but intuitive: introduce explicit marker to scan all packages.

openApiConfiguration.setResourcePackages(Collections.singleton("*"));

Another option would be to check Application instance for resource classes and allow the scanning of all packages only if this set is empty.

The feedback would be really appreciated, for now the desired results could be achieved with some smelly workarounds but it would be great to make the scanning outcomes obvious.

[1] https://issues.apache.org/jira/browse/CXF-8103

Thank you guys.
CC @frantuma

frantuma added a commit that referenced this pull request Sep 4, 2019
refs #3283 - add scanner limited to defined resourcePackages
@frantuma
Copy link
Member

frantuma commented Sep 4, 2019

Thanks for reporting this! the default behaviour has indeed changed in such a scenario since 2.0.7 (more as a side effect..) and wasn't documented; just merged #3284 introduces JaxrsApplicationAndResourcePackagesAnnotationScanner (see also updated wiki) which behaves as JaxrsApplicationAndAnnotationScanner in versions up to 2.0.6 and can be provided in configuration (therefore replacing this PR).

In current versions 2.0.6 - 2.0.9, the same behaviour can be achieved either using ApplicationScanner (only considering custom Application.classes()), or providing a custom scanner.

Let me know if this solves your issue and in this case please close PR.

@reta
Copy link
Contributor Author

reta commented Sep 4, 2019

Thanks a lot, @frantuma , makes perfect sense! Would you be interested in tests for JaxrsApplicationAndAnnotationScanner and JaxrsAnnotationScanner (in a separate PR)? I haven't found much tests for scanners, thank you!

@reta reta closed this Sep 4, 2019
@frantuma
Copy link
Member

frantuma commented Sep 4, 2019

tests are more than welcome, thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants