2

We are using Wildlfy 10 and Swagger 1.5.12 (Swagger 2.0 Spec) In our application we are deploying the contract and implementation of our webservice in our ear to ensure being able to exchange the implementation on this level. The war exposing our webservice is packaged in the same ear and has access to all its modules.

The swagger definition is placed in the war file. While the webservice endpoints are working as intended the swagger.json only contains the general information but does not contain the Api documentation.

After debugging a while i came to the following result:

  • The classes are discovered by the Scanner using reflections.getTypesAnnotatedWith(Api.class)

  • trying to generate the config afterwards they are using cls.getAnnotation(annotationClass) and alternatively cls.getAnnotations() and annotation = metaAnnotation.annotationType().getAnnotation(annotationClass); both return null

After debugging further i narrowed it down to the fact, that the Annotation attached to the class is loaded by the ear-classloader while swagger is using the war-classloader (as it is placed in the war). This is conform to the Wildlfy Documentation as war-modules use a different classloader.

Other questions were answered with

I think you'll end up with other issues with the multiple classloader issue source

and

To be honest it should be also said that when you load the same class in more than a ClassLoader it's quite easy getting other side effects, like static state duplication and so on. That's why I think the developers using swagger in exotic scenarios - like build systems integration - should be warned about the fact that the library uses reflection for code analysis, hence the classloader matters. source

Deploying the contract and ejb module in our war solved it, but unfortunately is no valid solution in our architecture.

Questions:

  1. Is there a (non hacky) way to load the swagger-annotations-jar in the ear module with the same classloader in bot the war and ear modules?

  2. Is it possible to solve this by tweaking the swagger configuration? (adjusting the implementation to not use reflection is only the last resort)

  3. Can this be seen as a bug of swagger?

Abaddon666
  • 1,533
  • 15
  • 31

0 Answers0