java - Swagger2 Change Base Path for Swagger Ui -
was able setup swagger 2 springboot app adding swaggerconfig file , adding following dependencies:
@configuration @enableswagger2 public class swaggerconfig { @bean public docket productapi() { return new docket(documentationtype.swagger_2).select().apis(requesthandlerselectors.any()) .paths(predicates.not(pathselectors.regex("/error"))).build().apiinfo(apiinfo()); } private apiinfo apiinfo() { apiinfo apiinfo = new apiinfo("motorcycle shop - restful services", "rest based api motorcycle shop", "1.0", "", new contact("", "", ""), "", ""); return apiinfo; } }
pom.xml
<parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.5.4.release</version> </parent> <dependencies> <!-- spring --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <!-- swagger --> <dependency> <groupid>io.springfox</groupid> <artifactid>springfox-swagger2</artifactid> <version>2.6.1</version> <scope>compile</scope> </dependency> <dependency> <groupid>io.springfox</groupid> <artifactid>springfox-swagger-ui</artifactid> <version>2.6.1</version> <scope>compile</scope> </dependency> </dependencies>
despite fact controller class looks this:
@restcontroller @requestmapping("/motorcycles") public class productcontroller { // method }
... still able invoke controller doing this:
curl -x http://localhost:8080/motorcycles
i have open swagger-ui.html file using following url path:
http://localhost:8080/swagger-ui.html
how can make spring boot app show (the actual app name or default requestmapping specified in controller - if controller 1 in app):
http://localhost:8080/motorcycles/swagger-ui.html
basically, how can prefix swagger-ui.html app name?
so, lets app called motorboy, want:
http://localhost:8080/motorboy/swagger-ui.html
and curl -x rest endpoint looks this:
http://localhost:8080/motorboy/motorcycles
it seems spring-boot using plain old http://localhost:8080 default app name in browser swagger.
Comments
Post a Comment