我将 springfox-swagger2 用于我的 Spring MVC REST API。一切都适用于 swagger,但我的问题是我无法在我的 swagger 文档中添加其他信息。
Maven依赖:
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
我的 Swagger 配置类:
@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan("path.to.controller.package")
public class SwaggerConfig {
@Bean
public Docket customImplementation() {
return new Docket(DocumentationType.SPRING_WEB).apiInfo(apiInfo());
}
@Bean
public UiConfiguration uiConfig() {
return UiConfiguration.DEFAULT;
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("Service API", "Simple REST Service", "0.0.1",
"mail@mail.com", "mail@mail.com", " ", " ");
return apiInfo;
}
}
我的控制器类:
@RestController
@RequestMapping("/persons")
public class PersonController {
Logger LOGGER = LoggerFactory.getLogger(PersonController.class);
@RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
@ApiOperation(value = "doStuff", response = Person.class)
@ApiImplicitParams({@ApiImplicitParam(name="Authorization", value="MY DESCRIPTION")})
public @ResponseBody Person getPerson(@PathVariable String id,
@RequestHeader(value = "Authorization") String authToken) throws Exception {
//do things and return
}
}
因此,调用 swagger-ui 会显示控制器、方法以及除我在@ApiOperation
和中定义的附加信息之外的所有内容@ApiImplicitParams
。有谁知道问题出在哪里?参数也不在从 swagger 创建的 JSON 文件中。