【发布时间】:2016-01-27 10:11:33
【问题描述】:
我通过包含依赖项向我的 Spring Boot 应用程序添加了 swagger:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.3.1</version>
</dependency>
并添加一个配置类:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(Predicates.or(PathSelectors.regex("...")))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(...);
}
}
我现在可以访问 /v2/api-docs 并获得一些似乎描述我的 API 的 JSON。然而,JSON 被包裹在另一个 JSON 对象中,像这样(缩写):
{"value":"{\"swagger\":\"2.0\",\"info\":...}
{"value": "..."} 对象不是必需的,它会导致 swagger-ui 中的错误。 PetStore 示例没有这个额外的级别。这是一个错误?还是配置问题?
PS:我还为此创建了一个github issue
【问题讨论】:
标签: spring spring-boot swagger swagger-2.0