fix(接口测试): 导入swagger报空指针
--bug=1048546 --user=陈建星 【接口测试】接口定义-导入swagger 接口文档接口的object下array内容信息没导入 https://www.tapd.cn/55049933/s/1631527
This commit is contained in:
parent
452402137a
commit
25f02084ec
|
@ -584,28 +584,40 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
|
||||||
|
|
||||||
private JsonSchemaItem parseSchema(Schema<?> schema, Set refModelSet) {
|
private JsonSchemaItem parseSchema(Schema<?> schema, Set refModelSet) {
|
||||||
if (schema != null) {
|
if (schema != null) {
|
||||||
|
if (StringUtils.equals(schema.getType(), PropertyConstant.NULL)) {
|
||||||
|
return parseNull();
|
||||||
|
}
|
||||||
return switch (schema) {
|
return switch (schema) {
|
||||||
case ArraySchema arraySchema -> parseArraySchema(arraySchema, refModelSet);
|
case ArraySchema arraySchema -> parseArraySchema(arraySchema, refModelSet);
|
||||||
case ObjectSchema objectSchema -> parseObject(objectSchema, refModelSet);
|
case ObjectSchema objectSchema -> parseObject(objectSchema, refModelSet);
|
||||||
case MapSchema mapSchema -> parseMapObject(mapSchema, refModelSet);
|
case MapSchema mapSchema -> parseMapObject(mapSchema, refModelSet);
|
||||||
|
case IntegerSchema integerSchema -> parseInteger(integerSchema);
|
||||||
|
case StringSchema stringSchema -> parseString(stringSchema);
|
||||||
|
case NumberSchema numberSchema -> parseNumber(numberSchema);
|
||||||
|
case BooleanSchema booleanSchema -> parseBoolean(booleanSchema);
|
||||||
default -> {
|
default -> {
|
||||||
if (StringUtils.isNotBlank(schema.get$ref())) {
|
if (StringUtils.isNotBlank(schema.get$ref())) {
|
||||||
yield parseObject(schema, refModelSet);
|
yield parseObject(schema, refModelSet);
|
||||||
}
|
}
|
||||||
yield parseSchemaBySimpleType(schema);
|
yield parseSchemaByType(schema, refModelSet);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonSchemaItem parseSchemaBySimpleType(Schema<?> schema) {
|
private JsonSchemaItem parseSchemaByType(Schema<?> schema, Set refModelSet) {
|
||||||
String type = schema.getType();
|
String type = schema.getType();
|
||||||
|
if (type == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case PropertyConstant.STRING -> parseString(schema);
|
case PropertyConstant.STRING -> parseString(schema);
|
||||||
case PropertyConstant.INTEGER -> parseInteger(schema);
|
case PropertyConstant.INTEGER -> parseInteger(schema);
|
||||||
case PropertyConstant.NUMBER -> parseNumber(schema);
|
case PropertyConstant.NUMBER -> parseNumber(schema);
|
||||||
case PropertyConstant.BOOLEAN -> parseBoolean(schema);
|
case PropertyConstant.BOOLEAN -> parseBoolean(schema);
|
||||||
|
case PropertyConstant.OBJECT -> parseObject(schema, refModelSet);
|
||||||
|
case PropertyConstant.ARRAY -> parseArraySchema(schema, refModelSet);
|
||||||
default -> {
|
default -> {
|
||||||
JsonSchemaItem jsonSchemaItem = new JsonSchemaItem();
|
JsonSchemaItem jsonSchemaItem = new JsonSchemaItem();
|
||||||
jsonSchemaItem.setId(IDGenerator.nextStr());
|
jsonSchemaItem.setId(IDGenerator.nextStr());
|
||||||
|
@ -628,16 +640,8 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
|
||||||
return jsonSchemaItem;
|
return jsonSchemaItem;
|
||||||
}
|
}
|
||||||
JsonSchemaItem item = new JsonSchemaItem();
|
JsonSchemaItem item = new JsonSchemaItem();
|
||||||
switch (value) {
|
if (value instanceof Schema<?> schema) {
|
||||||
case IntegerSchema integerSchema -> item = parseInteger(integerSchema);
|
item = parseSchema(schema, refModelSet);
|
||||||
case StringSchema stringSchema -> item = parseString(stringSchema);
|
|
||||||
case NumberSchema numberSchema -> item = parseNumber(numberSchema);
|
|
||||||
case BooleanSchema booleanSchema -> item = parseBoolean(booleanSchema);
|
|
||||||
case ArraySchema arraySchema -> item = parseArraySchema(arraySchema, refModelSet);
|
|
||||||
case ObjectSchema objectSchemaItem -> item = parseObject(objectSchemaItem, refModelSet);
|
|
||||||
case Schema schema -> item = parseSchema(schema, refModelSet);
|
|
||||||
default -> {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
jsonSchemaProperties.put(StringUtils.EMPTY, item);
|
jsonSchemaProperties.put(StringUtils.EMPTY, item);
|
||||||
jsonSchemaItem.setProperties(jsonSchemaProperties);
|
jsonSchemaItem.setProperties(jsonSchemaProperties);
|
||||||
|
@ -664,7 +668,7 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
|
||||||
}
|
}
|
||||||
if (MapUtils.isNotEmpty(properties)) {
|
if (MapUtils.isNotEmpty(properties)) {
|
||||||
properties.forEach((key, value) -> {
|
properties.forEach((key, value) -> {
|
||||||
JsonSchemaItem item = parseProperty(value, refModelSet);
|
JsonSchemaItem item = parseSchema(value, refModelSet);
|
||||||
jsonSchemaProperties.put(key, item);
|
jsonSchemaProperties.put(key, item);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -672,23 +676,6 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
|
||||||
return jsonSchemaItem;
|
return jsonSchemaItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonSchemaItem parseProperty(Schema<?> value, Set refModelSet) {
|
|
||||||
if (StringUtils.equals(value.getType(), PropertyConstant.NULL)) {
|
|
||||||
return parseNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
return switch (value) {
|
|
||||||
case IntegerSchema integerSchema -> parseInteger(integerSchema);
|
|
||||||
case StringSchema stringSchema -> parseString(stringSchema);
|
|
||||||
case NumberSchema numberSchema -> parseNumber(numberSchema);
|
|
||||||
case BooleanSchema booleanSchema -> parseBoolean(booleanSchema);
|
|
||||||
case ArraySchema arraySchema -> parseArraySchema(arraySchema, refModelSet);
|
|
||||||
case ObjectSchema objectSchema -> parseObject(objectSchema, refModelSet);
|
|
||||||
case MapSchema mapSchema -> parseMapObject(mapSchema, refModelSet);
|
|
||||||
case Schema<?> schema -> parseSchema(schema, refModelSet);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private JsonSchemaItem parseString(Schema stringSchema) {
|
private JsonSchemaItem parseString(Schema stringSchema) {
|
||||||
JsonSchemaItem jsonSchemaItem = parseSchemaItem(stringSchema);
|
JsonSchemaItem jsonSchemaItem = parseSchemaItem(stringSchema);
|
||||||
jsonSchemaItem.setType(PropertyConstant.STRING);
|
jsonSchemaItem.setType(PropertyConstant.STRING);
|
||||||
|
@ -750,8 +737,10 @@ public class Swagger3ParserApiDefinition extends HttpApiDefinitionImportAbstract
|
||||||
jsonSchemaArray.setMaxItems(arraySchema.getMaxItems());
|
jsonSchemaArray.setMaxItems(arraySchema.getMaxItems());
|
||||||
jsonSchemaArray.setMinItems(arraySchema.getMinItems());
|
jsonSchemaArray.setMinItems(arraySchema.getMinItems());
|
||||||
|
|
||||||
JsonSchemaItem itemsJsonSchema = parseProperty(arraySchema.getItems(), refModelSet);
|
JsonSchemaItem itemsJsonSchema = parseSchema(arraySchema.getItems(), refModelSet);
|
||||||
|
if (itemsJsonSchema != null) {
|
||||||
jsonSchemaArray.setItems(List.of(itemsJsonSchema));
|
jsonSchemaArray.setItems(List.of(itemsJsonSchema));
|
||||||
|
}
|
||||||
return jsonSchemaArray;
|
return jsonSchemaArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue