我们正在使用这些版本的SpringFox:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>2.6.1</version>
</dependency>
使用下面的bean实例化SpringFox / Swagger 2:
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.alternateTypeRules(
AlternateTypeRules.newRule(typeResolver.resolve(ResponseEntity.class, WildcardType.class),
typeResolver.resolve(WildcardType.class)))
.apiInfo(apiInfo());
}
我们使用ResponseEntity泛型作为返回类型:
@RequestMapping(value = “/someMethod”, method = RequestMethod.POST)
public ResponseEntity<?> someMethod(@RequestBody Application app) {
try {
return new ResponseEntity<>(aService.someMethod(app), HttpStatus.OK);
} catch (Exception ex) {
String errorMessage = ex + " <== error";
LOG.error(errorMessage, ex);
return new ResponseEntity<>(errorMessage, HttpStatus.BAD_REQUEST);
}
}
当我们尝试使用swagger-ui.html查看响应模型Schema时,使用ResponseEntity我们得到空模型模式{}。如果我们将返回类型更改为ResponseEntity,则会为响应填充模型架构。
我们想知道是否有办法使用注释或某些配置来替换模型规范/定义,其中ResponseEntity用于实际的类?
谢谢!