SwaggerUI + Jersey doesn't generate swagger.json file

1,147 views
Skip to first unread message

Rogger Tipiani

unread,
Feb 12, 2016, 10:44:37 AM2/12/16
to Swagger
Hello there,

I have some problems trying to start with SwaggerUI because Swagger doesn't generate the "swagger.json" file

I'm working with Eclipse and Tomcat 8, I downloaded the definition from here and I followed the instructions from here
As I understand there are 3 ways to configure swagger in your local repository based on your JERSEY configuration
I followed this one "Using Jersey 2 container Servlet or Filter (with web.xml)"
and these are the steps that I made for the project

1.- Created a Jersey Project using this Maven archetype

   
mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.22.1


2.- Added this SwaggerUI dependency to my POM file

       
        <dependency>
         
<groupId>io.swagger</groupId>
         
<artifactId>swagger-jersey2-jaxrs</artifactId>
         
<version>1.5.0</version>
       
</dependency>

3.- I Modified the Web.xml file, to add the Swagger "param-value" (Notice that my resource is in the package com.api, and the "url-pattern" value is "api" )
    
folowing the instructions from here


    <servlet>
       
<servlet-name>Jersey Web Application</servlet-name>
       
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
       
<init-param>
           
<param-name>jersey.config.server.provider.packages</param-name>
           
<param-value>io.swagger.jaxrs.listing,com.api</param-value>          
       
</init-param>
       
<load-on-startup>1</load-on-startup>
   
</servlet>
   
   
   
<servlet-mapping>
       
<servlet-name>Jersey Web Application</servlet-name>
       
<url-pattern>/api/*</url-pattern>
   
</servlet-mapping>




4.- And finally I added the Swagger Servlet into the Web.xml file, here is the full xml file (Notice the "swagger.api.basepath" value)


<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   
           
   
<servlet>
       
<servlet-name>Jersey Web Application</servlet-name>
       
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
       
<init-param>
           
<param-name>jersey.config.server.provider.packages</param-name>
           
<param-value>io.swagger.jaxrs.listing,com.api</param-value>          
       
</init-param>
       
<load-on-startup>1</load-on-startup>
   
</servlet>
   
   
   
<servlet-mapping>
       
<servlet-name>Jersey Web Application</servlet-name>
       
<url-pattern>/api/*</url-pattern>
   
</servlet-mapping>
   
   
<servlet>
       
<servlet-name>Jersey2Config</servlet-name>
       
<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
       
<init-param>
           
<param-name>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/SwaggerTest1/api/</param-value>
       
</init-param>
       
<load-on-startup>2</load-on-startup>
   
</servlet>
   
</web-app>



Acordingly to that guide this will generate a swagger.json file but It doesn't exist in my project.
there was a problem when I'm trying to give the path for swagger.api.basepath value ?
or maybe there is a problem with the "jersey.config.server.provider.packages" value ?


Additionals.

Here is MyResource.java class

package com.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;



/**
 * Root resource (exposed at "myresource" path)
 */

@Path("/myresource")
public class MyResource {

   
/**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */

   
@GET
   
@Produces(MediaType.TEXT_PLAIN)
   
public String getIt() {
       
return "Got it!";
   
}
}


and here is my project files





Ron Ratovsky

unread,
Feb 12, 2016, 2:06:35 PM2/12/16
to swagger-sw...@googlegroups.com
Swagger-core serves the swagger.json file at runtime and does not create a ‘physical’ file on your file system. Have you tried accessing the swagger.json file at runtime? If so, which URL(s) did you try?


   
publicString getIt(){
       
return"Got it!";
   
}
}


and here is my project files





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

RoggerElfo

unread,
Feb 12, 2016, 2:32:28 PM2/12/16
to Swagger
Thanks for your answer ! 

As I read, I just had to copy the "dist" folder that is inside the "swagger-ui-2.1.4" folder

The URL's that I tried are 





http://localhost:8080/SwaggerTest1/api - Following the web.xml (swagger.api.basepath value url path)

 
http://localhost:8080/SwaggerTest1/dist/ - Using the index.html that is inside the "dist" folder.





All links are broken =/
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
Feb 12, 2016, 3:05:46 PM2/12/16
to swagger-sw...@googlegroups.com
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

RoggerElfo

unread,
Feb 12, 2016, 3:14:24 PM2/12/16
to Swagger
Thank you so much Ron !! It Works !! 
Reply all
Reply to author
Forward
0 new messages