fix: swagger2 导入响应体

This commit is contained in:
chenjianxing 2021-03-30 12:05:52 +08:00
parent 11bb0cf5a4
commit 378c31e3ca
1 changed files with 14 additions and 7 deletions

View File

@ -149,6 +149,14 @@ public class Swagger2Parser extends SwaggerAbstractParser {
return getBodyType(contentType);
}
private String getResponseBodyType(Operation operation) {
if (CollectionUtils.isEmpty(operation.getProduces())) {
return Body.JSON;
}
String contentType = operation.getProduces().get(0);
return getBodyType(contentType);
}
private void parsePathParameters(Parameter parameter, List<KeyValue> rests) {
PathParameter pathParameter = (PathParameter) parameter;
rests.add(new KeyValue(pathParameter.getName(), "", getDefaultStringValue(parameter.getDescription())));
@ -175,14 +183,17 @@ public class Swagger2Parser extends SwaggerAbstractParser {
msResponse.getBody().setKvs(new ArrayList<>());
msResponse.setHeaders(new ArrayList<>());
msResponse.setType(RequestType.HTTP);
msResponse.getBody().setType(getBodyType(operation));
msResponse.getBody().setType(getResponseBodyType(operation));
// todo 状态码要调整
msResponse.setStatusCode(new ArrayList<>());
if (responses != null) {
if (responses != null && responses.size() > 0) {
responses.forEach((responseCode, response) -> {
msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode));
String body = parseSchema(response.getResponseSchema());
if (StringUtils.isNotBlank(body)) {
msResponse.getBody().setRaw(body);
}
parseResponseHeader(response, msResponse.getHeaders());
parseResponseBodyParameters(response, msResponse.getBody());
});
}
return msResponse;
@ -197,10 +208,6 @@ public class Swagger2Parser extends SwaggerAbstractParser {
}
}
private void parseResponseBodyParameters(Response response, Body body) {
body.setRaw(parseSchema(response.getResponseSchema()));
}
private void parseRequestBodyParameters(Parameter parameter, Body body) {
BodyParameter bodyParameter = (BodyParameter) parameter;
body.setRaw(parseSchema(bodyParameter.getSchema()));