I have a RESTful service based on Jersey 1.18.1 and I want to show my API through Swagger .
First, I have to get JSON. I read this instruction: Swagger Core Jersey 1.X Project Setup 1.5 . Swagger allows you to configure the configuration using various methods, and I decided to use my own subclass of Application. I did everything step by step, but I cannot get the JSON that I have to use for swagger-ui .
What I've done:
My user application
@ApplicationPath("api/v1") public class DiscountsApp extends Application{ public DiscountsApp() { BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.2"); beanConfig.setSchemes(new String[]{"http"}); beanConfig.setHost("localhost:8002"); beanConfig.setBasePath("swaggerapi"); beanConfig.setResourcePackage("alexiuscrow.diploma.endpoints"); beanConfig.setScan(true); } @Override public Set<Class<?>> getClasses() { Set<Class<?>> resources = new HashSet(); resources.add(ShopsResources.class);
ShopsResources
@Path("/shops") @Api(value="/shops", description="Shops") public class ShopsResources { @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "List shops", httpMethod = "GET", notes = "List nearest or locality shops", response = Shops.class, responseContainer = "List") public String getShops( @ApiParam( value = "Radius", required = false) @QueryParam("radius") String radiusParam, @ApiParam( value = "Latitude", required = true) @QueryParam("lat") String latParam, @ApiParam( value = "Longitude", required = true) @QueryParam("lng") String lngParam) throws SQLException{
Some dependencies on pom.xml
<dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-bundle</artifactId> <version>1.18.1</version> </dependency> <dependency> <groupId>com.wordnik</groupId> <artifactId>swagger-jersey-jaxrs</artifactId> <version>1.5.1-M2</version> </dependency>
After the application is deployed in Tomcat I tried to get http: // localhost: 8002 / swaggerapi , but I have no result.
I did not find swagger.json in the root of my application ( /tomcat8/webapps/app ).
What's wrong? How can I get JSON with my API?
source share