swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

BeanConfig incorrectly processes resourcePackage in jersey2-jaxrs module

Open igor-kostromin opened this issue 11 years ago • 3 comments

There are 2 problems I have found:

1. If specify inner package, outer will be scanned too.

See com.wordnik.swagger.jaxrs.config.BeanConfig#classesFromContext code:

val config = new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(resourcePackage)).setScanners(
      new TypeAnnotationsScanner(), new SubTypesScanner())
    new Reflections(config).getTypesAnnotatedWith(classOf[Api]).asScala.toList

ClasspathHelper.forPackage(resourcePackage) returns urls list like this:

file:/C:/all/my-backend/project1/target/classes/
file:/C:/all/my-backend/utils/target/classes/

And then search will be applied to all classes in these paths. So we can't specify package explicitly.

2. Multiple packages cannot be specified over the comma.

If use this syntax (described in wiki docs) scanner will print warning:

given scan urls are empty. set urls in the configuration

The cause of problem possibly is that classesFromContext method is not called in this case. Swagger calls beanConfig.classes() method instead. And classes() always returns empty list.

igor-kostromin avatar Jan 23 '15 14:01 igor-kostromin

If you can provide a unit test demonstrating this, I'd be happy to look into it more.

fehguy avatar Jan 24 '15 00:01 fehguy

Try this please https://github.com/elw00d/gretty-jersey-swagger-app/tree/master

igor-kostromin avatar Jan 27 '15 16:01 igor-kostromin

Added a filter to the BeanConfig.java class which will avoid this.

see https://github.com/swagger-api/swagger-core/blob/develop_2.0/modules/swagger-jaxrs/src/main/java/com/wordnik/swagger/jaxrs/config/BeanConfig.java#L145

fehguy avatar Mar 13 '15 20:03 fehguy