Swagger UI未在示例值中返回预期的JSON响应。它返回一个空列表。下面是我正在使用的代码片段,
Gradle依赖
compile('io.springfox:springfox-swagger-ui:2.9.2')
compile('io.springfox:springfox-swagger2:2.9.2')
Swagger配置
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.ignoredParameterTypes(HttpServletResponse.class)
.select() .apis(RequestHandlerSelectors.basePackage("com.core.controller.v2"))
.paths(PathSelectors.any())
.build()
.enable(true)
.apiInfo(apiInfo())
.securityContexts(Lists.newArrayList(securityContext()))
.securitySchemes(Lists.newArrayList(apiKey()));
调节器
@ApiOperation(value="A GET request to get a list of all contents for a given user.",
notes = "This API is used to get the contents for a given user with an NPI and Partner ID",
response = CoreContentItem.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success response", response = CoreContentItem.class,responseContainer = "List"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 400, message = "Bad Request",responseContainer = "String"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 500, message = "Internal Server Error, please contact system administrator")})
Swagger输出Swagger UI for success Response
预期的JSON响应
这是预期的JSON响应示例
[
{
"item": {
"id": "3f94ea1a687dda4af3e2",
"category": null,
"type": "EXTERNAL",
"headline": "DO NOT DELETE - REST ASSURED All - HIGH - JV",
"summary": "DO NOT DELETE - All - HIGH - JV",
"details": null,
"mediaURL": "",
"createdOn": 1493658088000,
"modifiedOn": 1495553312000,
"priority": "HIGH",
"startDate": 1493618400000,
"endDate": 1588312800000,
"feedbackEmail": null,
"totalLikes": 0,
"totalViews": 2,
"customData": null,
"userInteraction": {
"userLiked": false,
"userDisliked": false,
"userViewed": false
},
"availableActions": [
"View",
"Done",
"Submit"
],
"externalURL": "https://www.1234.com/vegetables/armando%25e2%2580%2599s-chiles-rellenos/r/5014"
}
}
]
我发现了这个问题。显然,这是一个模型映射异常,使Swagger UI返回一个空列表。现在我能够在示例值中看到模型。 enter image description here