refactor: 接口导入代码优化

This commit is contained in:
chenjianxing 2021-11-17 20:39:53 +08:00 committed by jianxing
parent 3f5ad742c9
commit 940902225c
2 changed files with 6 additions and 6 deletions

View File

@ -300,7 +300,7 @@ public class Swagger2Parser extends SwaggerAbstractParser {
item.setType("object");
handleRefProperties(item, value, refSet);
} else {
handleBaseProperties(item, value, refSet);
handleBaseProperties(item, value);
}
if (value.getExample() != null) {
item.getMock().put("mock", value.getExample());
@ -324,12 +324,12 @@ public class Swagger2Parser extends SwaggerAbstractParser {
subItem.setType("object");
subItem.setProperties(parseSchemaProperties(((ObjectProperty) value).getProperties(), refSet));
} else {
handleBaseProperties(subItem, value, refSet);
handleBaseProperties(subItem, value);
}
item.getItems().add(subItem);
}
private void handleBaseProperties(JsonSchemaItem item, Property value, HashSet<String> refSet) {
private void handleBaseProperties(JsonSchemaItem item, Property value) {
if (value instanceof StringProperty || value instanceof DateProperty || value instanceof DateTimeProperty ) {
item.setType("string");
} else if (value instanceof IntegerProperty) {

View File

@ -343,17 +343,17 @@ public class Swagger3Parser extends SwaggerAbstractParser {
private void parseKvBody(Schema schema, Body body, Object data, Map<String, Schema> infoMap) {
if (data instanceof JSONObject) {
((JSONObject) data).forEach((k, v) -> {
_parseKvBody(schema, body, k, infoMap);
parseKvBodyItem(schema, body, k, infoMap);
});
} else {
if(data instanceof Schema) {
Schema dataSchema = (Schema) data;
_parseKvBody(schema, body, dataSchema.getName(), infoMap);
parseKvBodyItem(schema, body, dataSchema.getName(), infoMap);
}
}
}
private void _parseKvBody(Object schemaObject, Body body, String name, Map<String, Schema> infoMap) {
private void parseKvBodyItem(Object schemaObject, Body body, String name, Map<String, Schema> infoMap) {
Schema schema = (Schema) schemaObject;
if (schema == null) return;
KeyValue kv = new KeyValue(name, String.valueOf(schema.getExample() == null ? "" : schema.getExample()), schema.getDescription());