在Swagger Java API中,当我使用responsecontainer =" List" (或" Set")代码= 400,我没有在Swagger-GUI上获得响应模型。我刚收到Array [Object]。
以下是具体案例:
@CrossOrigin
@RestController
@RequestMapping(value = "/api")
@Loggable(prepend = true, trim = false)
public class ConfigResource {
private final ConfigResourceDelegate delegate;
@Inject
public ConfigResource(final ConfigResourceDelegate delegate) {
this.delegate = delegate;
}
@RequestMapping(
value = "/v1/config",
method = PUT,
consumes = APPLICATION_JSON_UTF8_VALUE,
produces = APPLICATION_JSON_UTF8_VALUE
)
@ApiResponses(value = {@ApiResponse(code=202,message = "ACCEPTED" ),
@ApiResponse(code=200,response = Rejection.class, responseContainer
= "Set", message = "BAD_REQUEST"),
@ApiResponse(code=500, message = "INTERNAL_SERVER_ERROR")})
public ResponseEntity<?> putConfig(final @RequestBody ConfigDto
configDto){
return delegate.putConfig(riskConfigDto);
}
}
这是拒绝类:
public class Rejection {
private Long id;
private RejectionDTO rejection;
private String originMessage;
public Rejection() {
}
public Long getId() {
return id;
}
public RejectionDTO getRejection() {
return rejection;
}
public String getOriginMessage() {
return originMessage;
}
public void setId(Long id) {
this.id = id;
}
public void setRejection(RejectionDTO rejection) {
this.rejection = rejection;
}
public void setOriginMessage(String originMessage) {
this.originMessage = originMessage;
}
}
所以通常我应该在招摇的UI中的[]之间使用这个模型。但是,我得到了Array [Object]:
答案 0 :(得分:1)
要使您的示例正常工作,您需要将返回值从通配符ResponseEntity<?>
更改为具体类ResponseEntity<List<Rejection>>
。此外,您需要将responseContainer
从List
更改为Set
。
@RequestMapping(
value = "/v1/config",
method = PUT,
consumes = APPLICATION_JSON_UTF8_VALUE,
produces = APPLICATION_JSON_UTF8_VALUE
)
@ApiResponses(value = {@ApiResponse(code=202,message = "ACCEPTED" ),
@ApiResponse(code=200,response = Rejection.class, responseContainer
= "List", message = "BAD_REQUEST"),
@ApiResponse(code=500, message = "INTERNAL_SERVER_ERROR")})
public ResponseEntity<List<Rejection>> putConfig(final @RequestBody ConfigDto
configDto){
return delegate.putConfig(riskConfigDto);
}