我使用springfox-swagger2作为我的Spring MVC REST API . 一切都很好用,但我的问题是我不能在我的招摇文档中添加额外的信息 .
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
中定义的附加信息之外的所有内容 . 有没有人知道问题出在哪里? params也不在由swagger创建的JSON文件中 .
1 回答
尝试通过以下方式替换
customImplementation()
方法:构建项目,然后应显示您的其他信息 .
EDIT :我不知道它是否有任何区别,但我正在使用这些依赖项: