diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java index aef9e0a3a4..9998a14640 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java @@ -456,6 +456,9 @@ public class Swagger3Parser extends SwaggerAbstractParser { private JsonSchemaItem parseSchema(Schema schema, Set refSet) { if (schema == null) return null; + if (StringUtils.isBlank(schema.get$ref()) && schema.getProperties() == null && refSet.isEmpty()) { + return null; + } JsonSchemaItem item = new JsonSchemaItem(); if (schema.getRequired() != null) { item.setRequired(schema.getRequired()); @@ -478,16 +481,28 @@ public class Swagger3Parser extends SwaggerAbstractParser { } else if (schema instanceof ObjectSchema) { item.setType("object"); 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 { return null; } - if (schema.getExample() != null) { item.getMock().put("mock", schema.getExample()); } else { item.getMock().put("mock", ""); } + item.setDescription(schema.getDescription()); + item.setPattern(schema.getPattern()); + item.setMaxLength(schema.getMaxLength()); + item.setMinLength(schema.getMinLength()); + return item; } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java index 103c5772fe..d91772962c 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/variable/JsonSchemaItem.java @@ -22,7 +22,11 @@ public class JsonSchemaItem { private Map mock; private Map properties; private JsonSchemaItem additionalProperties; - private List required ; + private List required; + private String pattern; + private Integer maxLength; + private Integer minLength; + @JSONField(name = "$schema") private String schema; diff --git a/frontend/src/business/components/api/definition/components/body/ApiBody.vue b/frontend/src/business/components/api/definition/components/body/ApiBody.vue index b90c948acf..22808d53e9 100644 --- a/frontend/src/business/components/api/definition/components/body/ApiBody.vue +++ b/frontend/src/business/components/api/definition/components/body/ApiBody.vue @@ -222,11 +222,13 @@ export default { const MsConvert = new Convert(); if (this.body.format === 'JSON-SCHEMA') { - if (this.body.raw && !this.body.jsonSchema) { - this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw)); - } else { - let data = MsConvert.format(JSON.parse(this.body.raw)); - this.body.jsonSchema = this.deepAssign(this.body.jsonSchema, data); + if (this.body.raw) { + if (!this.body.jsonSchema) { + this.body.jsonSchema = MsConvert.format(JSON.parse(this.body.raw)); + } else { + let data = MsConvert.format(JSON.parse(this.body.raw)); + this.body.jsonSchema = this.deepAssign(this.body.jsonSchema, data); + } } } else { if (this.body.jsonSchema) {