I want to generate Swagger API documentation for ReST service developed using Jersey.
I have gone through Swagger API documentation and deployed as per the documentation.
But i am getting the following output when i access the URL (http://localhost:8080/MySwagger/swagger.json).
{
"swagger" : "2.0",
"info" :
{
"version" : "1.0.2",
"title" : "UUK"
},
"host" : "localhost:8080",
"basePath" : "/MySwagger",
"schemes" : [ "http" ]
}
The above one deosn't contain API that we have developed
I have tried the various options mentioned in the documentation but the result is same.
I have deployed the application in tomcat 7.0.68.
My Java version is 7
I have used maven to download the dependency Jars and manually copy the Jars to /WEB-INF/lib directory
Maven Script
mvn dependency:get -DgroupId=io.swagger -DartifactId=swagger-jersey2-jaxrs -Dversion=1.5.7
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
io.swagger.jaxrs.listing.ApiListingResource,
io.swagger.jaxrs.listing.SwaggerSerializers,
test.EventReceiver
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SwaggerBootstrap</servlet-name>
<servlet-class>test.bootstrap.SwaggerApplication</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
My Custom Servlet Class
import io.swagger.jaxrs.config.BeanConfig;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class SwaggerApplication extends HttpServlet
{
private static final long serialVersionUID = 1L;
@Override
public void init(ServletConfig config) throws ServletException
{
super.init(config);
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath(config.getServletContext().getContextPath());
beanConfig.setTitle("UUK");
beanConfig.setResourcePackage("io.swagger.resources");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}
}
My API Class
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path(value="/v1/")
@Api(value="inboundtransaction" ,description = "Receive Inbound transaction", position = 1, protocols = "http")
public class EventReceiver
{
@POST
@Path(value="/inboundtransaction")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@ApiOperation(value="Receiving Inbound transaction from X", notes = "Must Contain ID",httpMethod = "POST",response=String.class)
@ApiResponses(value =
{
@ApiResponse(code = 201, message = "Received request and process later", response=String.class),
@ApiResponse(code = 400, message = "Server Busy. Please re-send later", response=String.class)
}
)
public String inboundtransaction(
@ApiParam(value = "Pass mandatory values to create EdiAddress",required = true) String data
)
{
return "Success";
}
}
Please let me know what is the issue in the current setup.
Regards
Udhaya