fix(接口定义): 不同的状态码对应不同的Schema时,响应内容显示有误
--user=郭雨琦 --bug=1013977 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001013977
This commit is contained in:
parent
0ba31e7696
commit
866d693d1a
|
@ -263,25 +263,35 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
|||
msResponse.getBody().setType(getResponseBodyType(operation));
|
||||
// todo 状态码要调整?
|
||||
msResponse.setStatusCode(new ArrayList<>());
|
||||
Response response = null;
|
||||
String responseCode = null;
|
||||
if (responses != null && responses.size() > 0) {
|
||||
responses.forEach((responseCode, response) -> {
|
||||
if(StringUtils.isNotBlank(response.getDescription())){
|
||||
msResponse.getStatusCode().add(new KeyValue(responseCode, response.getDescription()));
|
||||
}else{
|
||||
msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode));
|
||||
}
|
||||
if (responseCode.equals("200")&&response.getResponseSchema()!=null) {
|
||||
parseResponseBody(response.getResponseSchema(),msResponse.getBody());
|
||||
msResponse.getBody().setFormat("JSON-SCHEMA");
|
||||
} else {
|
||||
String body = parseSchema(response.getResponseSchema());
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
msResponse.getBody().setRaw(body);
|
||||
}
|
||||
}
|
||||
parseResponseHeader(response, msResponse.getHeaders());
|
||||
});
|
||||
Map.Entry<String, Response> next = responses.entrySet().iterator().next();
|
||||
responseCode = next.getKey();
|
||||
response = next.getValue();
|
||||
}
|
||||
if (response!=null && responseCode!=null) {
|
||||
if (StringUtils.isNotBlank(response.getDescription())) {
|
||||
msResponse.getStatusCode().add(new KeyValue(responseCode, response.getDescription()));
|
||||
} else {
|
||||
msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode));
|
||||
}
|
||||
if (response.getResponseSchema()!=null) {
|
||||
parseResponseBody(response.getResponseSchema(),msResponse.getBody());
|
||||
msResponse.getBody().setFormat("JSON-SCHEMA");
|
||||
String body = parseSchema(response.getResponseSchema());
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
msResponse.getBody().setRaw(body);
|
||||
}
|
||||
} else {
|
||||
String body = parseSchema(response.getResponseSchema());
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
msResponse.getBody().setRaw(body);
|
||||
}
|
||||
}
|
||||
parseResponseHeader(response, msResponse.getHeaders());
|
||||
}
|
||||
|
||||
return msResponse;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue