Swagger - Jersey 2 configuration

767 views
Skip to first unread message

Federico De Faveri

unread,
Apr 29, 2015, 4:28:07 AM4/29/15
to swagger-sw...@googlegroups.com
I'm trying to use Swagger with Jersey 2 (without spring) but I'm not getting the swagger.json file.

My application uses Jersey 2 version 2.14 and Java 1.8.


Added swagger dependency to maven:

<dependency>
 <groupId>com.wordnik</groupId>
 <artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
 <version>1.3.12</version>
</dependency>

Configured Jersey to scan swagger packages:

@ApplicationPath("rest")
public class MyAplication extends ResourceConfig {
publicMyAplication() {
packages("com.wordnik.swagger.jersey.listing");

                ....

and finally configured swagger through the BeanConfig:

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.0");
        beanConfig.setBasePath("http://localhost:8080/myapp-web/rest");
        beanConfig.setResourcePackage("org.myapp.web.resource");
        beanConfig.setScan(true);

{"apiVersion":"1.0.0","swaggerVersion":"1.2"}

When I try to open http://localhost:8080/myapp-web/rest/api-docs/swagger.json I get a 404 error.

Ron Ratovsky

unread,
Apr 29, 2015, 4:34:01 AM4/29/15
to swagger-sw...@googlegroups.com
If this is a new integration, why don't you use the latest version of swagger-core?

Are your resources annotated with @Api?


--
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
-----------------------------------------

Federico De Faveri

unread,
Apr 29, 2015, 5:28:45 AM4/29/15
to swagger-sw...@googlegroups.com

I've updated the project to 1.5 core.

@ApplicationPath("rest")
public class MyAppAplication extends ResourceConfig {
public MyAppAplication() {
packages("com.wordnik.swagger.jaxrs.listing");
        
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/myapp-web/rest");
beanConfig.setResourcePackage("org.myapp.web.resource");
beanConfig.setScan(true);

I had to exclude Jersey dependencies from swagger, it takes 2.1 but I'm using 2.14.
I had to exclude Jackson dependecies from Jersey because swagger need an updated version.

Now when I open this url http://localhost:8080/myapp-web/rest/api-docs/ I get a 404 error.

Where is supposed to be the swagger.json?

I the log I see this:
11:20:41.053 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO  Reflections: Reflections took 13 ms to scan 1 urls, producing 11 keys and 19 values 

So I think something is working.


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,
Apr 29, 2015, 5:30:54 AM4/29/15
to swagger-sw...@googlegroups.com
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
-----------------------------------------

--
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.

Federico De Faveri

unread,
Apr 29, 2015, 5:49:16 AM4/29/15
to swagger-sw...@googlegroups.com
Found :). 
Thank you.

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.



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

--
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.

sumved shami

unread,
May 10, 2015, 1:24:05 AM5/10/15
to swagger-sw...@googlegroups.com
Hi Ron/Federico

I am trying swagger and jersey integration for the first time. Somehow, I am unable to see swagger.json page and the API responses.

I am looking for swagger.json page at: http://localhost:8080/akosha-api/api/swagger.json


I am using the same swagger document Federico is using.

My Application class is AkoshaApiApplication and it contains swagger bean configuration.
Please have a look at my pom.xml as well. Does it require to have swagger-ui plugins configurations? Anyway, doesn't effect anything. 

Can you please help me in resolving this issue?

Thank you.

Regards,
Sumved Shami




CIN No. U72900CH2009PTC031912

Ron Ratovsky

unread,
May 10, 2015, 2:07:06 AM5/10/15
to swagger-sw...@googlegroups.com
Are you able to access your own API?

--
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.

sumved shami

unread,
May 10, 2015, 2:08:44 AM5/10/15
to swagger-sw...@googlegroups.com

No! I am unable to access the API.

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/BV3Qha91vxI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

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

CIN No. U72900CH2009PTC031912

Ron Ratovsky

unread,
May 10, 2015, 2:14:27 AM5/10/15
to swagger-sw...@googlegroups.com
Okay, that's what you need to solve first then. It's not really related to Swagger and is a bit out of scope.
Once you have that working, you should be able to access the swagger.json file. Your configuration seems fine.

Thomas Pepio

unread,
May 26, 2015, 11:08:45 AM5/26/15
to swagger-sw...@googlegroups.com
Hi !

I believe I'm facing a similar issue as Federico.

Here's my configuration :

public ApiConfig() extends ResourceConfig {
    register(DomainEndpoint.class);
    packages("com.wordnik.swagger.jaxrs.listing");

    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setVersion("1.0.0");
    beanConfig.setResourcePackage("some.package.containing.swagger.documented.endpoint");
    beanConfig.setHost("http://localhost:8080");
    beanConfig.setBasePath("/api/");
    beanConfig.setTitle("A cool API");
    beanConfig.setScan(true);
}


I'm able to access my API at "http://localhost:8080/api/domain/1" (retrieves first object of "domain").

I'm unable to access any documentation at:
 - "http://localhost:8080/api/domain/api-docs/" (the latter call logicaljy falls into my endpoint).

Adding "swagger.json" at the end of both URLs does not work either.

I guess there's something I'm missing but can't figure out what.

Le dimanche 10 mai 2015 08:14:27 UTC+2, Ron a écrit :
Okay, that's what you need to solve first then. It's not really related to Swagger and is a bit out of scope.
Once you have that working, you should be able to access the swagger.json file. Your configuration seems fine.
On Sun, May 10, 2015 at 9:08 AM, sumved shami <sumved...@akosha.in> wrote:

No! I am unable to access the API.

On May 10, 2015 11:37, "Ron Ratovsky" <r...@swagger.io> wrote:
Are you able to access your own API?
On Sun, May 10, 2015 at 8:24 AM, sumved shami <sumved...@akosha.in> wrote:
Hi Ron/Federico

I am trying swagger and jersey integration for the first time. Somehow, I am unable to see swagger.json page and the API responses.

I am looking for swagger.json page at: http://localhost:8080/akosha-api/api/swagger.json


I am using the same swagger document Federico is using.

My Application class is AkoshaApiApplication and it contains swagger bean configuration.
Please have a look at my pom.xml as well. Does it require to have swagger-ui plugins configurations? Anyway, doesn't effect anything. 

Can you please help me in resolving this issue?

Thank you.

Regards,
Sumved Shami




CIN No. U72900CH2009PTC031912

--
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.



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

--
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/BV3Qha91vxI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

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

CIN No. U72900CH2009PTC031912

--
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,
May 26, 2015, 11:17:32 AM5/26/15
to swagger-sw...@googlegroups.com
Thomas,

Your question mixes both an older version of swagger-core and the new one. I really can't help without more information, specifically the swagger-core version you use.
I'd suggest just following the guides we have in the wiki to integrate the latest version with your application. They're fairly straightforward.
If you still have a problem after integrating those, feel free to ping us again.

BR,
Ron

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
-----------------------------------------

--
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/BV3Qha91vxI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

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

CIN No. U72900CH2009PTC031912

--
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
-----------------------------------------

--
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.

Thomas Pepio

unread,
May 26, 2015, 11:56:28 AM5/26/15
to swagger-sw...@googlegroups.com
Hi Ron,

Thank you for you reply, do you refer to the old version of swagger because of the use of ResourceConfig class ?

I'm using swagger-core and swagger-jersey2-jaxrs, both come in version 1.5.2-M2.
I also updated my configuration : 

@ApplicationPath("/api")
public class ApiConfig extends Application {

    public ApiConfig() {
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.0");
        beanConfig.setResourcePackage("some.package.containing.swagger.documented.endpoint");
        beanConfig.setScan(true);
        beanConfig.setPrettyPrint("true");
        beanConfig.setSchemes(new String[] {"http"});
        beanConfig.setHost("localhost:8080");
        beanConfig.setBasePath("/doc");
        beanConfig.setTitle("A cool API");
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<Class<?>>();
        resources.add(DomainEndpoint.class);

        resources.add(com.wordnik.swagger.jaxrs.listing.ApiListingResource.class);
        resources.add(com.wordnik.swagger.jaxrs.listing.SwaggerSerializers.class);

        return resources;
    }
}

I'm now able to access some documentation at "http://localhost:8080/api/swagger.json"
I'm unable to access some documentation at :

(adding swagger.json at the end of all previous URL won't work either).

I'm trying to figure out what the "basePath" parameter works.


Regards,
Thomas.
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.



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

--
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/BV3Qha91vxI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

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

CIN No. U72900CH2009PTC031912

--
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.



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

--
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.

Thomas Pepio

unread,
May 26, 2015, 12:10:11 PM5/26/15
to swagger-sw...@googlegroups.com
It's me again, just to say that my previous configuration actually works !

What I lacked : @Api(value = ..., description = ...) on top of my endpoint :/

Sorry for the disturbance, and again thank you for you reply.

Regards,
Thomas.
Message has been deleted

Ron Ratovsky

unread,
May 26, 2015, 2:18:53 PM5/26/15
to swagger-sw...@googlegroups.com
No worries, Thomas, thanks for the update.
There are a few subtle but important differences between 1.3 and 1.5, which is why I suggested going through the wiki.
I assumed you're trying 1.3 since you were looking for api-docs.

On Tue, May 26, 2015 at 12:11 PM, Thomas Pepio <tpe...@octo.com> wrote:
It's me again, just to say that my previous configuration actually works !

What I lacked : @Api(value = ..., description = ...) on top of my endpoint :/

Sorry for the disturbance, and again thank you for you reply.

Regards,
Thomas.

Le mardi 26 mai 2015 17:56:28 UTC+2, Thomas Pepio a écrit :
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
-----------------------------------------

--
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/BV3Qha91vxI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

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

CIN No. U72900CH2009PTC031912

--
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
-----------------------------------------

--
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
-----------------------------------------

--
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.
Reply all
Reply to author
Forward
0 new messages