fix(接口测试): 解决swagger3导入时高级配置的问题
--user=郭雨琦 --bug=1014740 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014740
This commit is contained in:
parent
2306bfda73
commit
d380b20a6d
|
@ -456,6 +456,9 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
|
|
||||||
private JsonSchemaItem parseSchema(Schema schema, Set<String> refSet) {
|
private JsonSchemaItem parseSchema(Schema schema, Set<String> refSet) {
|
||||||
if (schema == null) return null;
|
if (schema == null) return null;
|
||||||
|
if (StringUtils.isBlank(schema.get$ref()) && schema.getProperties() == null && refSet.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
JsonSchemaItem item = new JsonSchemaItem();
|
JsonSchemaItem item = new JsonSchemaItem();
|
||||||
if (schema.getRequired() != null) {
|
if (schema.getRequired() != null) {
|
||||||
item.setRequired(schema.getRequired());
|
item.setRequired(schema.getRequired());
|
||||||
|
@ -478,16 +481,28 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
} else if (schema instanceof ObjectSchema) {
|
} else if (schema instanceof ObjectSchema) {
|
||||||
item.setType("object");
|
item.setType("object");
|
||||||
item.setProperties(parseSchemaProperties(schema, refSet));
|
item.setProperties(parseSchemaProperties(schema, refSet));
|
||||||
|
} else if (schema instanceof StringSchema) {
|
||||||
|
item.setType("string");
|
||||||
|
} else if (schema instanceof IntegerSchema) {
|
||||||
|
item.setType("integer");
|
||||||
|
} else if (schema instanceof NumberSchema) {
|
||||||
|
item.setType("number");
|
||||||
|
} else if (schema instanceof BooleanSchema) {
|
||||||
|
item.setType("boolean");
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.getExample() != null) {
|
if (schema.getExample() != null) {
|
||||||
item.getMock().put("mock", schema.getExample());
|
item.getMock().put("mock", schema.getExample());
|
||||||
} else {
|
} else {
|
||||||
item.getMock().put("mock", "");
|
item.getMock().put("mock", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
item.setDescription(schema.getDescription());
|
item.setDescription(schema.getDescription());
|
||||||
|
item.setPattern(schema.getPattern());
|
||||||
|
item.setMaxLength(schema.getMaxLength());
|
||||||
|
item.setMinLength(schema.getMinLength());
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,10 @@ public class JsonSchemaItem {
|
||||||
private Map<String, JsonSchemaItem> properties;
|
private Map<String, JsonSchemaItem> properties;
|
||||||
private JsonSchemaItem additionalProperties;
|
private JsonSchemaItem additionalProperties;
|
||||||
private List<String> required;
|
private List<String> required;
|
||||||
|
private String pattern;
|
||||||
|
private Integer maxLength;
|
||||||
|
private Integer minLength;
|
||||||
|
|
||||||
|
|
||||||
@JSONField(name = "$schema")
|
@JSONField(name = "$schema")
|
||||||
private String schema;
|
private String schema;
|
||||||
|
|
|
@ -222,12 +222,14 @@ export default {
|
||||||
const MsConvert = new Convert();
|
const MsConvert = new Convert();
|
||||||
|
|
||||||
if (this.body.format === 'JSON-SCHEMA') {
|
if (this.body.format === 'JSON-SCHEMA') {
|
||||||
if (this.body.raw && !this.body.jsonSchema) {
|
if (this.body.raw) {
|
||||||
|
if (!this.body.jsonSchema) {
|
||||||
this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw));
|
this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw));
|
||||||
} else {
|
} else {
|
||||||
let data = MsConvert.format(JSON.parse(this.body.raw));
|
let data = MsConvert.format(JSON.parse(this.body.raw));
|
||||||
this.body.jsonSchema = this.deepAssign(this.body.jsonSchema, data);
|
this.body.jsonSchema = this.deepAssign(this.body.jsonSchema, data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.body.jsonSchema) {
|
if (this.body.jsonSchema) {
|
||||||
MsConvert.schemaToJsonStr(this.body.jsonSchema, (result) => {
|
MsConvert.schemaToJsonStr(this.body.jsonSchema, (result) => {
|
||||||
|
|
Loading…
Reference in New Issue