fix: swagger2.0导入body为空

This commit is contained in:
chenjianxing 2021-01-22 18:06:18 +08:00
parent 4144a35a26
commit 5f8ecf76cf
2 changed files with 14 additions and 3 deletions

View File

@ -69,7 +69,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method.name()); ApiDefinitionResult apiDefinition = buildApiDefinition(request.getId(), operation, pathName, method.name());
parseParameters(operation, request); parseParameters(operation, request);
apiDefinition.setRequest(JSON.toJSONString(request)); apiDefinition.setRequest(JSON.toJSONString(request));
apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation.getResponses()))); apiDefinition.setResponse(JSON.toJSONString(parseResponse(operation, operation.getResponses())));
buildModule(parentNode, apiDefinition, operation.getTags(), importRequest.isSaved()); buildModule(parentNode, apiDefinition, operation.getTags(), importRequest.isSaved());
results.add(apiDefinition); results.add(apiDefinition);
} }
@ -163,11 +163,13 @@ public class Swagger2Parser extends SwaggerAbstractParser {
"", parameter.getRequired()); "", parameter.getRequired());
} }
private HttpResponse parseResponse(Map<String, Response> responses) { private HttpResponse parseResponse(Operation operation, Map<String, Response> responses) {
HttpResponse msResponse = new HttpResponse(); HttpResponse msResponse = new HttpResponse();
msResponse.setBody(new Body()); msResponse.setBody(new Body());
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));
// todo 状态码要调整 // todo 状态码要调整
msResponse.setStatusCode(new ArrayList<>()); msResponse.setStatusCode(new ArrayList<>());
if (responses != null) { if (responses != null) {
@ -234,6 +236,15 @@ public class Swagger2Parser extends SwaggerAbstractParser {
} }
} }
return propertyList.toString(); return propertyList.toString();
} else if (schema instanceof ModelImpl) {
ModelImpl model = (ModelImpl) schema;
if (StringUtils.equals("object", model.getType())) {
model.getProperties();
if (model != null) {
JSONObject bodyParameters = getBodyParameters(model.getProperties(), new HashSet<>());
return bodyParameters.toJSONString();
}
}
} }
return ""; return "";
} }

View File

@ -314,7 +314,7 @@ public class ApiDefinitionService {
} else { } else {
//如果存在则修改 //如果存在则修改
apiDefinition.setId(sameRequest.get(0).getId()); apiDefinition.setId(sameRequest.get(0).getId());
apiDefinitionMapper.updateByPrimaryKey(apiDefinition); apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
} }
return apiDefinition; return apiDefinition;
} }