java - Can't get json from Swagger + Jersey -
i have restful service based on jersey 1.18.1 , want show api via swagger.
firstly have json. read instruction: swagger core jersey 1.x project setup 1.5. swagger allows set configuration different methods , decided use custom application subclass. did step step can't json have use swagger-ui.
what did:
custom 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 serialized string //using custom gson serializer , know //that there better method of solution of task. } } }
some dependencies 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 deploy application tomcat tried http://localhost:8002/swaggerapi i've got no result.
didn't find swagger.json
in root of application (/tomcat8/webapps/app
).
what's wrong?
how can json api?
i not correctly built url.
correct: http://{host}:{port}/{context root of application}/{path @applicationpath
}/swagger.json
in case: http://localhost:8080/app/api/v1/swagger.json
thx ron.
Comments
Post a Comment