I tried a sample application which is simple rest service as below
HelloWorldService.java
package com.mkyong.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Path("/hello")
@Api("Hello World Service")
public class HelloWorldService {
@GET
@Path("/{param}")
@ApiOperation("Get Hello Message")
public Response getMsg(@PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
RestApplication.java
package rest;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import com.mkyong.rest.HelloWorldService;
public class RestApplication extends Application{
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(HelloWorldService.class);
s.add(io.swagger.jaxrs.listing.ApiListingResource.class);
s.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
return s;
}
}
Bootstrap.java
package servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import io.swagger.jaxrs.config.BeanConfig;
public class Bootstrap 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("RESTfulExample");
beanConfig.setResourcePackage("com.mkyong.rest");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}
}
web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>rs-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>rest.RestApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>rs-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SwaggerBootstrap</servlet-name>
<servlet-class>servlet.Bootstrap</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
With above configuration, i ran the server and hit the
http://localhost:8080/RESTfulExample/rest/hello/Rams, got the response "Jersey say : Rams",
But not able to find any swagger.json/yaml in the context root folder.. I tried as below..
http://localhost:8080/RESTfulExample/swagger.json
Can you let me know where i went wrong regarding the swagger documentation.
Please follow the documentation at https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X.
--
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.
You need to make sure to implement one of the methods described in https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X#hooking-up-swagger-core-in-your-application based on the jax-rs framework that you use.
--
Hi Ron, I followed the same steps.. I am elaborating step wise1. Adding dependency to the application<dependencies><dependency><groupId>io.swagger</groupId><artifactId>swagger-jersey2-jaxrs</artifactId><version>1.5.0</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.8.2</version><scope>test</scope></dependency><dependency><groupId>org.glassfish.jersey.core</groupId><artifactId>jersey-server</artifactId><version>2.6</version></dependency><dependency><groupId>org.glassfish.jersey.containers</groupId><artifactId>jersey-container-servlet</artifactId><version>2.6</version></dependency><dependency><groupId>org.glassfish.jersey.test-framework</groupId><artifactId>jersey-test-framework-core</artifactId><version>2.13</version></dependency><dependency><groupId>org.glassfish.jersey.test-framework.providers</groupId><artifactId>jersey-test-framework-provider-grizzly2</artifactId><version>2.13</version></dependency></dependencies>