fix: swagger2 导入响应体
This commit is contained in:
parent
11bb0cf5a4
commit
378c31e3ca
|
@ -149,6 +149,14 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
||||||
return getBodyType(contentType);
|
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) {
|
private void parsePathParameters(Parameter parameter, List<KeyValue> rests) {
|
||||||
PathParameter pathParameter = (PathParameter) parameter;
|
PathParameter pathParameter = (PathParameter) parameter;
|
||||||
rests.add(new KeyValue(pathParameter.getName(), "", getDefaultStringValue(parameter.getDescription())));
|
rests.add(new KeyValue(pathParameter.getName(), "", getDefaultStringValue(parameter.getDescription())));
|
||||||
|
@ -175,14 +183,17 @@ public class Swagger2Parser extends SwaggerAbstractParser {
|
||||||
msResponse.getBody().setKvs(new ArrayList<>());
|
msResponse.getBody().setKvs(new ArrayList<>());
|
||||||
msResponse.setHeaders(new ArrayList<>());
|
msResponse.setHeaders(new ArrayList<>());
|
||||||
msResponse.setType(RequestType.HTTP);
|
msResponse.setType(RequestType.HTTP);
|
||||||
msResponse.getBody().setType(getBodyType(operation));
|
msResponse.getBody().setType(getResponseBodyType(operation));
|
||||||
// todo 状态码要调整?
|
// todo 状态码要调整?
|
||||||
msResponse.setStatusCode(new ArrayList<>());
|
msResponse.setStatusCode(new ArrayList<>());
|
||||||
if (responses != null) {
|
if (responses != null && responses.size() > 0) {
|
||||||
responses.forEach((responseCode, response) -> {
|
responses.forEach((responseCode, response) -> {
|
||||||
msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode));
|
msResponse.getStatusCode().add(new KeyValue(responseCode, responseCode));
|
||||||
|
String body = parseSchema(response.getResponseSchema());
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
msResponse.getBody().setRaw(body);
|
||||||
|
}
|
||||||
parseResponseHeader(response, msResponse.getHeaders());
|
parseResponseHeader(response, msResponse.getHeaders());
|
||||||
parseResponseBodyParameters(response, msResponse.getBody());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return msResponse;
|
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) {
|
private void parseRequestBodyParameters(Parameter parameter, Body body) {
|
||||||
BodyParameter bodyParameter = (BodyParameter) parameter;
|
BodyParameter bodyParameter = (BodyParameter) parameter;
|
||||||
body.setRaw(parseSchema(bodyParameter.getSchema()));
|
body.setRaw(parseSchema(bodyParameter.getSchema()));
|
||||||
|
|
Loading…
Reference in New Issue