Spring Fox (Swagger) 2.9.2's Autogenerated swagger-ui is Not Showing Interactive API
Using Spring Fox 2.9.2 with Spring Boot 2.1.5 RELEASE, I am not able to use the interactive UI generated by Swagger.
This is with the REST Endpoints not expanded:
This is with the REST Endpoint expanded (as you can see there's no text field to type the id inside):
Maven pom.xml:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> </dependencies>
Swagger2Config.java:
package com.myservice.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2).select() .apis(RequestHandlerSelectors .basePackage("com.myservice")) .paths(PathSelectors.any()) .build() .apiInfo(apiEndPointsInfo()); } private ApiInfo apiEndPointsInfo() { return new ApiInfoBuilder().title("MyService API") .description("Buildings you measure.") .contact(new Contact(null, null, null)) .license("Apache 2.0") .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .version("1.0.0") .build(); } }
Also noticed is that I didn't need to use any Swagger specific annotations (e.g.@ApiOperation & @ApiResponse) inside the RestController (I did try putting them above getByUsingId(Integer id) method, and whereas my documentation was visible it still didn't have the id text field):
RestController:
@RequestMapping(value = {"/{id}" }, method = RequestMethod.GET, produces = "APPLICATION/JSON") public ResponseEntity<Object> getByUsingId(@PathVariable(value = "id", required = true) Integer id) throws IOException { MyResponse response = myDao.getById(id); if (response == null) { return new ResponseEntity<Object>(HttpStatus.NOT_FOUND); } return new ResponseEntity<Object>(response, headers, HttpStatus.OK); }
Comparing this to an old Spring Boot 1.5.6 RELEASE project, Spring Fox 2.6.1 has a much better UI and it is interactive (notice the better colors and the visible text field when expanded):
This look & feel (along with the interactive text fields) is exactly, what I want and need...
Question(s):
1. Is this a possible bug (the non-interactive text field) in Spring Fox 2.9.2?
2. Why is the swagger-ui looked dumbed down (the colors being different & not being so sharp looking, etc)?
Since, this forum stated "Message cannot exceed 20,000 characters.", I posted my question on Stack Overflow (SO):
The SO post contains the pom.xml, Swagger2Config.java, RestController.java code from my older Spring Boot project which works.