Tutorial for Swagger + JAX-RS

4,957 views
Skip to first unread message

tony tam

unread,
Jun 27, 2012, 3:35:34 AM6/27/12
to swagger-sw...@googlegroups.com
Hi all, I've posted a tutorial for getting running with Wordnik Swagger with Java + JAX-RS:


Feedback welcome!
Tony

Zhiyi Liu

unread,
Jul 3, 2012, 10:11:26 PM7/3/12
to swagger-sw...@googlegroups.com
Hi Tony,

Thanks for the great tutorial. However, I've had a hard time getting my simple app work with Swagger. I've attached the app with this email. It's a very simple Jetty+Jersey web app and I've followed your tutorial to make the changes. When I compiled it, I got this following error. 

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \orders\src\main\java\com\joejag\code\orders\restservices\OrdersService.java:[16,0] error: package com.wordnik.swagger.annotations
[ERROR] \orders\src\main\java\com\joejag\code\orders\restservices\OrdersService.java:[25,1] error: cannot find symbol
[ERROR] \orders\src\main\java\com\joejag\code\orders\restservices\OrdersService.java:[45,23] error: cannot find symbol
[ERROR] \orders\src\main\java\com\joejag\code\orders\restservices\OrdersService.java:[42,4] error: cannot find symbol
[ERROR] \orders\src\main\java\com\joejag\code\orders\restservices\OrdersService.java:[43,5] error: cannot find symbol

How can I add the annotations package to my project through Maven? I tried, but I couldn't make it work. I'd really appreciate it if you can help me on this.

Thanks,
Zhiyi
orders.zip

tony tam

unread,
Jul 4, 2012, 12:58:48 AM7/4/12
to swagger-sw...@googlegroups.com
Hi Zhiyi,
Two changes were required to get it to run:

1) The swagger annotations weren't in the maven repo when you tried this--I've pushed 1.0.2 which includes them--it'll be available anytime now.  In the mean time I updated your pom.xml to include 1.1-SNAPSHOT

2) The OrdersService.java needed the .{format} in the path (the tutorial shows how you can take this requirement away) as well as a content type:

@Path("orders.json")
@Api(value = "/orders", description = "Operation about orders")
@Produces("application/json")

After doing these two changes, it all works fine.  Note that if you want to run the swagger UI from your file system, you'll need to add an "allows-origin" header (see tutorial).

Tony

ps the version of jersey that you spefied (1.4) is pretty old--you should consider a newer version (1.7 or later).

Zhiyi Liu

unread,
Jul 4, 2012, 2:18:55 AM7/4/12
to swagger-sw...@googlegroups.com
Hi Tony,

Thanks so much for helping me out. Could you please send me the modified orders.zip?

Regards,
Zhiyi

tony tam

unread,
Jul 4, 2012, 3:29:16 AM7/4/12
to swagger-sw...@googlegroups.com
Yes, sending directly to you.


On Wednesday, June 27, 2012 12:35:34 AM UTC-7, tony tam wrote:

Zhiyi Liu

unread,
Jul 4, 2012, 5:47:14 PM7/4/12
to swagger-sw...@googlegroups.com
Thank you!
Reply all
Reply to author
Forward
0 new messages