Can't get json from Swagger + Jersey

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); //... resources.add(com.wordnik.swagger.jaxrs.listing.ApiListingResource.class); resources.add(com.wordnik.swagger.jaxrs.listing.SwaggerSerializers.class); return resources; } } 

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{ //The list of Shops objects is serialized to string //using the custom GSON serializer and I know //that there is the better method of the solution of this task. } } } 

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?

+5
source share
2 answers

I did not build the URL correctly.

Correct:

http: // {host}: {port} / {context root of the application} / {path from @ApplicationPath } /swagger.json

In my case: http: // localhost: 8080 / app / api / v1 / swagger.json

Thanks to Ron .

+3
source

adding a relative path for me (this is using .netcore 1.1)

 app.UseSwaggerUI(s => { s.RoutePrefix = "help"; s.SwaggerEndpoint("../swagger/v1/swagger.json", "MySite"); s.InjectStylesheet("../css/swagger.min.css"); }); 
-1
source

All Articles