refactor(接口测试): 优化接口定义导入导出
This commit is contained in:
parent
85f06fb2a5
commit
467be9b526
|
@ -219,9 +219,7 @@ public class Swagger3ExportParser implements ExportParser<ApiExportResponse> {
|
||||||
((JSONObject) bodyInfo).put("example", body.optJSONObject("rawBody").optString("value"));
|
((JSONObject) bodyInfo).put("example", body.optJSONObject("rawBody").optString("value"));
|
||||||
}
|
}
|
||||||
} else if (bodyType != null && bodyType.equalsIgnoreCase(Body.BodyType.XML.name())) {
|
} else if (bodyType != null && bodyType.equalsIgnoreCase(Body.BodyType.XML.name())) {
|
||||||
String xmlText = body.optString("xmlBody");
|
String xmlText = body.optJSONObject("xmlBody").optString("value");
|
||||||
JSONObject xmlObject = JSONUtil.parseObject(xmlText);
|
|
||||||
xmlText = xmlObject.optString("value");
|
|
||||||
String xml = XMLUtil.delXmlHeader(xmlText);
|
String xml = XMLUtil.delXmlHeader(xmlText);
|
||||||
int startIndex = xml.indexOf("<", 0);
|
int startIndex = xml.indexOf("<", 0);
|
||||||
int endIndex = xml.indexOf(">", 0);
|
int endIndex = xml.indexOf(">", 0);
|
||||||
|
@ -235,6 +233,7 @@ public class Swagger3ExportParser implements ExportParser<ApiExportResponse> {
|
||||||
schemas = new LinkedList<>();
|
schemas = new LinkedList<>();
|
||||||
}
|
}
|
||||||
schemas.add(jsonObject);
|
schemas.add(jsonObject);
|
||||||
|
jsonInfo = xml;
|
||||||
} else if (bodyType != null && bodyType.equalsIgnoreCase(Body.BodyType.WWW_FORM.name())) {
|
} else if (bodyType != null && bodyType.equalsIgnoreCase(Body.BodyType.WWW_FORM.name())) {
|
||||||
String wwwFormBody = body.optString("wwwFormBody");
|
String wwwFormBody = body.optString("wwwFormBody");
|
||||||
JSONObject wwwFormObject = JSONUtil.parseObject(wwwFormBody);
|
JSONObject wwwFormObject = JSONUtil.parseObject(wwwFormBody);
|
||||||
|
|
|
@ -290,8 +290,7 @@ public class Swagger3Parser extends ApiImportAbstractParser<ApiDefinitionImport>
|
||||||
case MediaType.APPLICATION_XML_VALUE -> {
|
case MediaType.APPLICATION_XML_VALUE -> {
|
||||||
body.setBodyType(Body.BodyType.XML.name());
|
body.setBodyType(Body.BodyType.XML.name());
|
||||||
XmlBody xml = new XmlBody();
|
XmlBody xml = new XmlBody();
|
||||||
//xml.setValue(XMLUtils.jsonToXmlStr(jsonValue));
|
String xmlBody = parseXmlBody(value, jsonSchemaItem);
|
||||||
String xmlBody = parseXmlBody(value.getSchema(), jsonSchemaItem);
|
|
||||||
xml.setValue(xmlBody);
|
xml.setValue(xmlBody);
|
||||||
body.setXmlBody(xml);
|
body.setXmlBody(xml);
|
||||||
}
|
}
|
||||||
|
@ -335,8 +334,7 @@ public class Swagger3Parser extends ApiImportAbstractParser<ApiDefinitionImport>
|
||||||
case MediaType.APPLICATION_XML_VALUE -> {
|
case MediaType.APPLICATION_XML_VALUE -> {
|
||||||
body.setBodyType(Body.BodyType.XML.name());
|
body.setBodyType(Body.BodyType.XML.name());
|
||||||
XmlBody xml = new XmlBody();
|
XmlBody xml = new XmlBody();
|
||||||
//xml.setValue(XMLUtils.jsonToXmlStr(jsonValue));
|
String xmlBody = parseXmlBody(value, jsonSchemaItem);
|
||||||
String xmlBody = parseXmlBody(value.getSchema(), jsonSchemaItem);
|
|
||||||
xml.setValue(xmlBody);
|
xml.setValue(xmlBody);
|
||||||
body.setXmlBody(xml);
|
body.setXmlBody(xml);
|
||||||
}
|
}
|
||||||
|
@ -361,8 +359,12 @@ public class Swagger3Parser extends ApiImportAbstractParser<ApiDefinitionImport>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseXmlBody(Schema schema, JsonSchemaItem jsonSchemaItem) {
|
private String parseXmlBody(io.swagger.v3.oas.models.media.MediaType value, JsonSchemaItem jsonSchemaItem) {
|
||||||
|
Schema schema = value.getSchema();
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
|
if (value.getExample() != null) {
|
||||||
|
return value.getExample().toString();
|
||||||
|
}
|
||||||
|
|
||||||
if (jsonSchemaItem != null && MapUtils.isNotEmpty(jsonSchemaItem.getProperties())) {
|
if (jsonSchemaItem != null && MapUtils.isNotEmpty(jsonSchemaItem.getProperties())) {
|
||||||
if (StringUtils.isNotBlank(schema.get$ref()) && schema.get$ref().split("/").length > 3) {
|
if (StringUtils.isNotBlank(schema.get$ref()) && schema.get$ref().split("/").length > 3) {
|
||||||
|
|
Loading…
Reference in New Issue