api-docs json URL (swagger.api.basepath) is always comming back empty with just the API version

1,845 views
Skip to first unread message

Oussama M Billah

unread,
Nov 26, 2014, 11:12:41 AM11/26/14
to swagger-sw...@googlegroups.com
Hi,

I m trying to setup swagger to work with my implementation using annotations.

I using CXF ( non-spring version) and jackson as a provider and ant as a build tool.

I tried to follow the tutorial in this URL with trying to modify it to use the non-spring version.

https://github.com/swagger-api/swagger-core/tree/master/samples/java-jaxrs-cxf

My Service is accessible from

http://localhost:8080/MobileStoreService/rest/product/12345

Here is my web.xml

<servlet>
   
<servlet-name>MobileStoreServlet</servlet-name>
   
<servlet-class>
           org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
     
</servlet-class>
   
<init-param>
     
<param-name>jaxrs.serviceClasses</param-name>
     
<param-value>com.company.integration.mobile.rest.MobileStoreService,com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON</param-value>
   
</init-param>
   
<init-param>
       
<param-name>jaxrs.providers</param-name>
       
<param-value>com.wordnik.swagger.jaxrs.json.JacksonJsonProvider,com.wordnik.swagger.jaxrs.listing.ResourceListingProvider,com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider</param-value>
   
</init-param>
   
<init-param>
     
<param-name>swagger.api.version</param-name>
     
<param-value>1.0</param-value>
   
</init-param>
   
<init-param>
       
<param-name>swagger.api.basepath</param-name>
       
<param-value>http://localhost:8080/MobileStoreService/rest/api-docs</param-value>
     
</init-param>
   
<load-on-startup>1</load-on-startup>
 
</servlet>
 
<servlet-mapping>
   
<servlet-name>MobileStoreServlet</servlet-name>
   
<url-pattern>/rest/*</url-pattern>
 
</servlet-mapping>


Here is my CXF Service class

@Produces({ "application/json" })
@Api (value = "/", description = "Manage people")
public class MobileStoreService {

   
/**
     * Return a Product based on the provided Product ID.
     * @param id
     * @return a Product product Object.
     */

   
@GET
   
@Path("/product/{id}/")
   
@ApiOperation(value = "Get a single product", notes = "Get a single product", response = Product.class)
   
public Product getProduct(@PathParam("id") final String id) {
         
// logic to retrieve Product
       
return product;
   
}


Here is all the dependencies that I have



When I run the application and hit

http://localhost:8080/MobileStoreService/rest/api-docs

I get the following response:
{"apiVersion":"0.0","swaggerVersion":"1.2"}



Can you please advise on why swagger is not detecting the annotation and generating the documentation for the GetProduct Service.

Ron

unread,
Nov 26, 2014, 1:11:12 PM11/26/14
to swagger-sw...@googlegroups.com
You should use the BeanConfig class and set the packages swagger-core needs to scan.

There are many examples for it in the google group, so I won't repeat it.

By the way, the Spring CXF sample uses the BeanConfig as well as a Spring bean, it's pretty much the same concept here.

Let me know if this works out for you.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oussama M Billah

unread,
Nov 26, 2014, 2:16:39 PM11/26/14
to swagger-sw...@googlegroups.com
Thanks Ron,

I have created a BeanConfig class inside my Service constructor so it gets initialized on startup and it worked.

Can the beanConfig configuration be moved to the web.xml rather than having to hard code the values in the code (no spring context here)?

Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Nov 26, 2014, 3:32:23 PM11/26/14
to swagger-sw...@googlegroups.com
The BeanConfig can't be moved directly.

There are two options - the first, you can use the DefaultJaxrsConfig servlet like here - https://github.com/swagger-api/swagger-core/blob/e32403e87aea6e43abec2660d8459116b3352725/samples/java-jaxrs-no-annotations/src/main/webapp/WEB-INF/web.xml#L33-L53 - that would make Swagger scan *all* resources, whether they are loaded by CXF or not.

An alternative solution is to wrap the BeanConfig with a servlet on your own, and pass the parameters as init-params, and setting those to the BeanConfig inside the servlet.

Hope this helps.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Oussama M Billah

unread,
Nov 27, 2014, 10:28:44 AM11/27/14
to swagger-sw...@googlegroups.com
Thanks Ron,

When I deployed the app on Jboss, I got the following exception from the BeanConfig.classesFromContext(..) method.

Any idea what can be causing this exception?


 WARNING [Reflections] could not create Vfs.Dir from url. ignoring the exception and continuing
org
.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [vfszip:/opt/jboss-eap-5.1.2/jboss-as/server/sim-uat-api/deploy/simons-service-api-1.0.2014-11-26-502eabd5c8f0745b7c53c2163ab70f80c3f06da8.ear/atglib/_Simstore.ServiceAPI_sclasses_s/]
either
use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
        at org
.reflections.vfs.Vfs.fromURL(Vfs.java:109)
        at org
.reflections.vfs.Vfs.fromURL(Vfs.java:91)
        at org
.reflections.Reflections.scan(Reflections.java:231)
        at org
.reflections.Reflections.scan(Reflections.java:204)
        at org
.reflections.Reflections.<init>(Reflections.java:129)
        at com
.wordnik.swagger.jaxrs.config.BeanConfig.classesFromContext(BeanConfig.scala:60)
        at com
.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1$$anonfun$apply$1$$anonfun$apply$2.apply(ApiListing.scala:42)
        at com
.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1$$anonfun$apply$1$$anonfun$apply$2.apply(ApiListing.scala:40)
        at scala
.Option.map(Option.scala:145)


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron

unread,
Nov 27, 2014, 11:05:28 AM11/27/14
to swagger-sw...@googlegroups.com
Can't say that I do. Can you share how you use the BeanConfig in your code?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Oussama M Billah

unread,
Nov 27, 2014, 11:08:42 AM11/27/14
to swagger-sw...@googlegroups.com
I m creating in the BeanConfig in the constructor of my CXF Service class as follow


 
/**

 * Constructor.

 */


 
public MobileStoreService() {


   
int port = atgConf.getSiteHttpServerPort();
 
   
String basePath = String.format("http://%s:%d/MobileStoreService/rest", hostName, port);

 
BeanConfig beanConfig = new BeanConfig();

 beanConfig
.setVersion("1.0");

 beanConfig
.setScan(true);

 beanConfig
.setResourcePackage(MobileStoreService.class.getPackage().getName());

 beanConfig
.setBasePath(basePath);

 

 
}

Ron

unread,
Nov 27, 2014, 11:10:45 AM11/27/14
to swagger-sw...@googlegroups.com
Try moving the setScan(true) to be the last call.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Oussama M Billah

unread,
Nov 27, 2014, 12:02:32 PM11/27/14
to swagger-sw...@googlegroups.com
Just did. it produced the same Exception!

Ron

unread,
Nov 27, 2014, 12:39:43 PM11/27/14
to swagger-sw...@googlegroups.com
Which version of swagger-core do you use?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Oussama M Billah

unread,
Nov 27, 2014, 12:51:45 PM11/27/14
to swagger-sw...@googlegroups.com
I m using swagger-core_2.10-1.3.10

Ron

unread,
Nov 27, 2014, 12:55:22 PM11/27/14
to swagger-sw...@googlegroups.com
And just to be certain, you're using it as a maven dependency?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Oussama M Billah

unread,
Nov 27, 2014, 1:04:19 PM11/27/14
to swagger-sw...@googlegroups.com
Nope, I m not using maven in this project. However, I add the swagger-jaxrs as a dependency on another maven project and saved all the generated jar files into my ant project. here is the list of jars that I have

Oussama M Billah

unread,
Nov 27, 2014, 1:08:53 PM11/27/14
to swagger-sw...@googlegroups.com
Capture.JPG

Ron

unread,
Nov 27, 2014, 1:21:33 PM11/27/14
to swagger-sw...@googlegroups.com
Any chance there's an additional reflections-X.jar hiding somewhere in the class path?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Oussama M Billah

unread,
Nov 27, 2014, 3:36:54 PM11/27/14
to swagger-sw...@googlegroups.com
I checked that and the only one that is found is the reflections-0.9.9-RC1.jar

Ron

unread,
Nov 28, 2014, 3:17:22 AM11/28/14
to swagger-sw...@googlegroups.com
I'm pretty much out of ideas.

If you can provide us with a runnable test-case that reproduces this issue, we may be able to solve it.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ashwin

unread,
Jan 29, 2015, 5:41:01 PM1/29/15
to swagger-sw...@googlegroups.com
Hi,

Are you able to resolve this issue? I am having same issues. 
I am creating BeanConfig initialized as servlet deploying on Jboss. 

Maven dependency:

<dependency>

<groupId>com.wordnik</groupId>

<artifactId>swagger-jaxrs_2.10</artifactId>

</dependency>


Please let me know if the resolution is found.

Ron Ratovsky

unread,
Jan 29, 2015, 5:45:09 PM1/29/15
to swagger-sw...@googlegroups.com
Which version do you use?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Ashwin

unread,
Jan 29, 2015, 5:57:44 PM1/29/15
to swagger-sw...@googlegroups.com
Are you referring to core version. Then it is swagger-core_2.10-1.3.1.jar.

Ron Ratovsky

unread,
Jan 29, 2015, 6:06:29 PM1/29/15
to swagger-sw...@googlegroups.com
It's time to upgrade to 1.3.12.

On Thu, Jan 29, 2015 at 5:57 PM, Ashwin <ashwin.da...@gmail.com> wrote:
Are you referring to core version. Then it is swagger-core_2.10-1.3.1.jar.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashwin

unread,
Jan 29, 2015, 7:08:51 PM1/29/15
to swagger-sw...@googlegroups.com
I didn't have direct dependency on core. Do you know which version of swagger-jaxrs has swagger-core-1.3.12? Thanks!

Ashwin

unread,
Jan 29, 2015, 7:25:53 PM1/29/15
to swagger-sw...@googlegroups.com
please ignore my previous comment.

Ashwin

unread,
Jan 29, 2015, 10:04:57 PM1/29/15
to swagger-sw...@googlegroups.com
I have bumped up the version to 1.3.12 but issue still persists.

Ron Ratovsky

unread,
Jan 29, 2015, 10:06:37 PM1/29/15
to swagger-sw...@googlegroups.com
You should really provide more details about your own use case and configuration. It was a long time ago and the original topic may or may not be related to your problem.

On Thu, Jan 29, 2015 at 10:04 PM, Ashwin <ashwin.da...@gmail.com> wrote:
I have bumped up the version to 1.3.12 but issue still persists.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashwin

unread,
Jan 29, 2015, 11:36:28 PM1/29/15
to swagger-sw...@googlegroups.com
I am using Jaxrs for creating rest services. I used below version of swagger-jaxrs.

  <groupId>com.wordnik</groupId>

  <artifactId>swagger-jaxrs_2.10</artifactId>

  <version>1.3.12</version>


Created a bean config as servlet. Below is the code snippet.

    @Override

    public void init(ServletConfig config) throws ServletException {

        super.init(config);


        BeanConfig beanConfig = new BeanConfig();

        beanConfig.setVersion("1.0");

        beanConfig.setBasePath("http://localhost:8080/my_services/api");

      //  beanConfig.setResourcePackage("io.swagger.resources");

        beanConfig.setResourcePackage(MyResource.class.getPackage().getName());

        beanConfig.setScan(true);

    }


Please let me know if you need more details. Thanks for your support.
Here is the stack trace I am seeing when I invoke the /api-docs URI.


2015-01-30 04:20:24,635 WARN  [http-0.0.0.0-8080-1] [] [Reflections] Could not get URL
java.io.FileNotFoundException: {Path to the WAR File}/WEB-INF/classes (Is a directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:214)
at java.util.zip.ZipFile.<init>(ZipFile.java:144)
at java.util.jar.JarFile.<init>(JarFile.java:153)
at java.util.jar.JarFile.<init>(JarFile.java:90)
at org.reflections.vfs.UrlTypeVFS.createDir(UrlTypeVFS.java:39)
at org.reflections.vfs.Vfs$DefaultUrlTypes$5.createDir(Vfs.java:264)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:98)
at org.reflections.vfs.Vfs.fromURL(Vfs.java:90)
at org.reflections.Reflections.scan(Reflections.java:236)
at org.reflections.Reflections.scan(Reflections.java:203)
at org.reflections.Reflections.<init>(Reflections.java:128)
at com.wordnik.swagger.jaxrs.config.BeanConfig.classesFromContext(BeanConfig.scala:60)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1$$anonfun$apply$1$$anonfun$apply$2.apply(ApiListing.scala:42)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1$$anonfun$apply$1$$anonfun$apply$2.apply(ApiListing.scala:40)
at scala.Option.map(Option.scala:145)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1$$anonfun$apply$1.apply(ApiListing.scala:40)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1$$anonfun$apply$1.apply(ApiListing.scala:39)
at scala.Option.map(Option.scala:145)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1.apply(ApiListing.scala:39)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$$anonfun$listing$1.apply(ApiListing.scala:37)
at scala.Option.orElse(Option.scala:257)
at com.wordnik.swagger.jaxrs.listing.ApiListingCache$.listing(ApiListing.scala:37)
at com.wordnik.swagger.jaxrs.listing.ApiListingResource.resourceListing(ApiListing.scala:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
.....

Ron Ratovsky

unread,
Jan 30, 2015, 11:45:59 AM1/30/15
to swagger-sw...@googlegroups.com

Can you check which version of reflections.org ends up on your application? You can check using mvn dependency:list

Which application server do you use? Does it have shared libraries that include reflections.org? Do you have other applications on the same app server that may contain that dependency?

--

Ashwin

unread,
Jan 30, 2015, 12:40:56 PM1/30/15
to swagger-sw...@googlegroups.com
I am using reflections-0.9.9.jar. I have verified my deployment directory and this is the only version that I have. I am using Jboss 5.2.

Ron Ratovsky

unread,
Jan 30, 2015, 1:39:16 PM1/30/15
to swagger-sw...@googlegroups.com

That can actually be the issue. JBoss 5 may carry it in its shared libraries. I need to check but will only be able to do that tomorrow.

On Jan 30, 2015 12:40 PM, "Ashwin" <ashwin.da...@gmail.com> wrote:
I am using reflections-0.9.9.jar. I have verified my deployment directory and this is the only version that I have. I am using Jboss 5.2.

--

Ashwin

unread,
Jan 30, 2015, 1:55:22 PM1/30/15
to swagger-sw...@googlegroups.com
I have verified JBOSS/server/<configuration>/lib and JBOSS/lib. Let me know what you find out.

Ron Ratovsky

unread,
Jan 30, 2015, 2:00:25 PM1/30/15
to swagger-sw...@googlegroups.com

I will when I get a chance. Unfortunately I'm between flights so it's difficult at the moment. There could be a thick jar too. I'll see if I can check before my next flight.

If I recall correctly, the version supplies with JBoss has a different name but uses the same class signatures.

On Jan 30, 2015 1:55 PM, "Ashwin" <ashwin.da...@gmail.com> wrote:
I have verified JBOSS/server/<configuration>/lib and JBOSS/lib. Let me know what you find out.

--

Ashwin

unread,
Feb 2, 2015, 1:23:56 PM2/2/15
to swagger-sw...@googlegroups.com
Did you get a chance to find out the jar that might be causing the issue?

Ron Ratovsky

unread,
Feb 2, 2015, 2:42:31 PM2/2/15
to swagger-sw...@googlegroups.com
Sorry, completely slipped my mind (jet lag). I'll look into it shortly.

On Mon, Feb 2, 2015 at 8:23 PM, Ashwin <ashwin.da...@gmail.com> wrote:
Did you get a chance to find out the jar that might be causing the issue?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashwin

unread,
Feb 3, 2015, 10:30:01 AM2/3/15
to swagger-sw...@googlegroups.com
Any luck?

Ron Ratovsky

unread,
Feb 4, 2015, 9:30:16 AM2/4/15
to swagger-sw...@googlegroups.com
Okay, my bad. It's may not be directly related to reflections.org but rather the javassist library which should be in the shared lib directory.

Do you have the option to try the application (at least the Swagger generation) on a different server such as Jetty or Tomcat?

On Tue, Feb 3, 2015 at 5:30 PM, Ashwin <ashwin.da...@gmail.com> wrote:
Any luck?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vel

unread,
Feb 4, 2015, 2:32:54 PM2/4/15
to swagger-sw...@googlegroups.com
Hi Ron, 

I doubt the issue is with the shared lib. I am also facing the exact issue (FileNotFound in UrlTypeVFS createDirectory). When I debugged, the flow is through this exact class and hence I don't see any contradiction with other Jboss lib.

Questions:


Is there a way to use org.jboss.virtual.VFS instaed of org.reflections.VFS.UrlTypeVFS in BeanConfig/Reflections? or
Is there a way to give the list of classes (including interface, as DefaultJaxrsConfig is not scanning interfaces) in BeanConfig? I can get the list of classes from package through org.jboss.virtual.VFS 

Thanks,
Vel



On Wednesday, February 4, 2015 at 6:30:16 AM UTC-8, Ron wrote:
Okay, my bad. It's may not be directly related to reflections.org but rather the javassist library which should be in the shared lib directory.

Do you have the option to try the application (at least the Swagger generation) on a different server such as Jetty or Tomcat?
On Tue, Feb 3, 2015 at 5:30 PM, Ashwin <ashwin.da...@gmail.com> wrote:
Any luck?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Feb 4, 2015, 2:36:53 PM2/4/15
to swagger-sw...@googlegroups.com
How do you specify the classes/packages that are loaded by Jersey?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Vel

unread,
Feb 4, 2015, 5:07:45 PM2/4/15
to swagger-sw...@googlegroups.com
We are using resteasy (jboss 5.1). All the classes are set by overriding the getClassesMethod in the class which extends Application.

For swagger we added the beanconfig in the constructor of the class that extends Application and sets the package name in ResourcePackage 

Ron Ratovsky

unread,
Feb 4, 2015, 5:17:06 PM2/4/15
to swagger-sw...@googlegroups.com
Can you share the code for the Application class(es)?

On Thu, Feb 5, 2015 at 12:07 AM, Vel <pra...@gmail.com> wrote:
We are using resteasy (jboss 5.1). All the classes are set by overriding the getClassesMethod in the class which extends Application.

For swagger we added the beanconfig in the constructor of the class that extends Application and sets the package name in ResourcePackage 

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vel

unread,
Feb 4, 2015, 5:45:19 PM2/4/15
to swagger-sw...@googlegroups.com
Here is the class.
 
public class App extends javax.ws.rs.core.Application
{
    public App() {
        super();
        
            BeanConfig beanConfig = new BeanConfig();
            beanConfig.setVersion("0.0.1");
            beanConfig.setBasePath("url"); 
            beanConfig.setResourcePackage("com.package");         
            beanConfig.setScan(true);
    }
    
    @Override
    public Set<Class<? >> getClasses()
    {
        Set<Class<? >> classSet = new HashSet<Class<? >>();
        classSet.add(com.package.class);
        ...

tony tam

unread,
Feb 5, 2015, 7:43:22 AM2/5/15
to swagger-sw...@googlegroups.com
Hi, chiming in late here, but it seems like the solution is to make your own version of BeanConfig.  It's actually a very simple class, please take a look here:


Don't get scared by the scala syntax, you can easily make a java class that does the exact same thing, and uses whatever scanning technique you want.  Give that a shot and post back, or please help make a simple, stand-alone sample that exhibits the problem.

Vel

unread,
Feb 9, 2015, 1:14:06 PM2/9/15
to swagger-sw...@googlegroups.com
The issue is resolved. 
Solution:
1. Create a custom scanner class which extends JaxScanner

public class CustomClassScanner implements JaxrsScanner
{
    

    @Override
    public List<Class<? >> classes()
    {
        Class[] ts = getClassesWithSwaggerAnnotations();
        List<Class<?>> result = List$.MODULE$.empty();
        for (int i = ts.length; i > 0; i--)
        {
            result = new $colon$colon(ts[i - 1], result);
        }
        return result;
    }





    @Override
    public List<Class<? >> classesFromContext(Application arg0, ServletConfig arg1)
    {
        Class[] ts = getClassesWithSwaggerAnnotations();
        List<Class<?>> result = List$.MODULE$.empty();
        for (int i = ts.length; i > 0; i--)
        {
            result = new $colon$colon(ts[i - 1], result);
        }
        return result;
    }

}

getClassesWithSwaggerAnnotations() method returns an Array of classes that needs to be scanned.

2. In the constructor of the class which extends Application, set the CustomClassScanner in ScannerFactory

public App() {
        super();
       
         SwaggerConfig swaggerConfig = new SwaggerConfig();
         ConfigFactory.setConfig(swaggerConfig);
         swaggerConfig.setApiVersion("1.0.0");
         swaggerConfig.setBasePath("http://localhost:8080/...");
         
         CustomClassScanner customClassScanner = new CustomClassScanner(); 
         ScannerFactory.setScanner(customClassScanner);
         ClassReaders.setReader(new DefaultJaxrsApiReader());
         
    }

Oussama M Billah

unread,
Mar 13, 2015, 12:01:54 PM3/13/15
to swagger-sw...@googlegroups.com
Here is what worked for me. I extended the BeanConfig and used a different approach to get the classes. then use the CustomBeanConfig in your code instead of BeanConfig.
make sure you have scala-library and swagger-core on your eclipse classpath.

import java.util.HashSet;

import java.util.Set;

import javax.servlet.ServletConfig;

import javax.ws.rs.core.Application;

import scala.collection.JavaConverters$;

import scala.collection.TraversableOnce;

import scala.collection.immutable.List;

import com.wordnik.swagger.jaxrs.config.BeanConfig;



public class CustomBeanConfig extends BeanConfig {

@Override

public List classesFromContext(Application app, ServletConfig sc) {

Set set = new HashSet();

System.out.println("CALLING CustomBeanConfig.classesFromContext()");

try {

// you can read the package name form some configuration or pass it as an constructor parameter to your new CustomBeanConfig

set.add(Class.forName("com.package.classWithSwaggerAnnotation"));

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return ((TraversableOnce) JavaConverters$.MODULE$.asScalaSetConverter(set).asScala()).toList();

}

}


--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/Xbo4XtLrThw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Elad Tabak

unread,
Jul 26, 2015, 2:58:36 AM7/26/15
to Swagger, pra...@gmail.com
Helped me a lot. Thanks!

Guru Yeshwanth

unread,
Jul 27, 2015, 12:27:40 PM7/27/15
to Swagger, obi...@gmail.com

Hello I am having similar issues as you but this is Apache CXF using spring.

Please help me out.

Regards,
Guru

On Wednesday, November 26, 2014 at 9:12:41 AM UTC-7, Oussama M Billah wrote:
Hi,

I m trying to setup swagger to work with my implementation using annotations.

I using CXF ( non-spring version) and jackson as a provider and ant as a build tool.

I tried to follow the tutorial in this URL with trying to modify it to use the non-spring version.

https://github.com/swagger-api/swagger-core/tree/master/samples/java-jaxrs-cxf

My Service is accessible from

http://localhost:8080/MobileStoreService/rest/product/12345

Here is my web.xml

<servlet>
   
<servlet-name>MobileStoreServlet</servlet-name>
   
<servlet-class>
           org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
     
</servlet-class>
   
<init-param>
     
<param-name>jaxrs.serviceClasses</param-name>
     
<param-value>com.company.integration.mobile.rest.MobileStoreService,com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON</param-value>
   
</init-param>
   
<init-param>
       
<param-name>jaxrs.providers</param-name>
       
<param-value>com.wordnik.swagger.jaxrs.json.JacksonJsonProvider,com.wordnik.swagger.jaxrs.listing.ResourceListingProvider,com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider</param-value>
   
</init-param>
   
<init-param>
     
<param-name>swagger.api.version</param-name>
     
<param-value>1.0</param-value>
   
</init-param>
   
<init-param>
       
<param-name>swagger.api.basepath</param-name>
       
<param-value>http://localhost:8080/MobileStoreService/rest/api-docs</param-value>
     
</init-param>
   
<load-on-startup>1</load-on-startup>
 
</servlet>
 
<servlet-mapping>
   
<servlet-name>MobileStoreServlet</servlet-name>
   
<url-pattern>/rest/*</url-pattern>
 
</servlet-mapping>


Here is my CXF Service class

@Produces({ "application/json" })
@Api (value = "/", description = "Manage people")
public class MobileStoreService {

   
/**
     * Return a Product based on the provided Product ID.
     * @param id
     * @return a Product product Object.
     */

   
@GET
   
@Path("/product/{id}/")
   
@ApiOperation(value = "Get a single product", notes = "Get a single product", response = Product.class)
   
public Product getProduct(@PathParam("id") final String id) {
         
// logic to retrieve Product
       
return product;
   
}


Here is all the dependencies that I have



When I run the application and hit

http://localhost:8080/MobileStoreService/rest/api-docs

I get the following response:
{"apiVersion":"0.0","swaggerVersion":"1.2"}



Can you please advise on why swagger is not detecting the annotation and generating the documentation for the GetProduct Service.

Jaya Reddy

unread,
Mar 18, 2016, 4:55:00 AM3/18/16
to Swagger
Hi Oussama M Billah,

Am also triying for the same but am facing the below warning.

After deploying the war file in Tomcat, am facing the below warning while trying to get the api_docs using the URL: http://localhost:8080/swagger/rest/api_docs/

WARNING:

Mar 17, 2016 6:10:00 PM org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor processRequest
WARNING: No root resource matching request path /swagger/rest/api_docs/ has been found, Relative Path: /api_docs/. Please enable FINE/TRACE log level for more details.
Mar 17, 2016 5:58:23 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.NotFoundException
at org.apache.cxf.jaxrs.utils.SpecExceptions.toNotFoundException(SpecExceptions.java:87)
at org.apache.cxf.jaxrs.utils.ExceptionUtils.toNotFoundException(ExceptionUtils.java:126)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:184)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:88)

Am i missing any where please suggest me.

Regards,
Jaya Reddy
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages