fix(接口自动化): json 处理

This commit is contained in:
fit2-zhao 2020-12-31 18:49:23 +08:00
parent d29c8bf2a2
commit 9c4e5bfbdb
3 changed files with 11 additions and 6 deletions

View File

@ -34,12 +34,12 @@
created() { created() {
if (!this.body.jsonSchema && this.body.raw) { if (!this.body.jsonSchema && this.body.raw) {
let obj = {"root": GenerateSchema(JSON.parse(this.body.raw))} let obj = {"root": GenerateSchema(JSON.parse(this.body.raw))}
this.body.jsonSchema = obj; this.schema = obj;
this.schema = this.body.jsonSchema;
} }
else if (this.body.jsonSchema) { else if (this.body.jsonSchema) {
this.schema = this.body.jsonSchema; this.schema = {"root": this.body.jsonSchema};
} }
this.body.jsonSchema = this.schema.root;
}, },
data() { data() {
return { return {
@ -57,7 +57,7 @@
methods: { methods: {
handleClick() { handleClick() {
if (this.activeName === 'preview') { if (this.activeName === 'preview') {
this.preview = schemaToJson(Object.values(this.schema)[0]); this.preview = schemaToJson(this.schema.root);
} }
}, },
openOneClickOperation() { openOneClickOperation() {

View File

@ -21,7 +21,7 @@
</el-select> </el-select>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<ms-mock :schema="pickValue"/> <ms-mock :disabled="pickValue.type==='object'" :schema="pickValue"/>
</el-col> </el-col>
<el-col> <el-col>
<el-input v-model="pickValue.description" class="ant-col-title" :placeholder="local['description']" size="small"/> <el-input v-model="pickValue.description" class="ant-col-title" :placeholder="local['description']" size="small"/>
@ -220,6 +220,7 @@
this.$delete(this.pickValue, 'properties') this.$delete(this.pickValue, 'properties')
this.$delete(this.pickValue, 'items') this.$delete(this.pickValue, 'items')
this.$delete(this.pickValue, 'required') this.$delete(this.pickValue, 'required')
this.$delete(this.pickValue, 'mock')
if (this.isArray) { if (this.isArray) {
this.$set(this.pickValue, 'items', {type: 'string', mock: {mock: ""}}) this.$set(this.pickValue, 'items', {type: 'string', mock: {mock: ""}})
} }

View File

@ -2,10 +2,10 @@
<div> <div>
<el-autocomplete <el-autocomplete
size="small" size="small"
:disabled="false"
class="input-with-autocomplete" class="input-with-autocomplete"
v-model="mock.mock" v-model="mock.mock"
:fetch-suggestions="funcSearch" :fetch-suggestions="funcSearch"
:disabled="disabled"
:placeholder="$t('api_test.value')" :placeholder="$t('api_test.value')"
value-key="name" value-key="name"
highlight-first-item highlight-first-item
@ -31,6 +31,7 @@
default: () => { default: () => {
} }
}, },
disabled: Boolean,
}, },
data() { data() {
return { return {
@ -43,6 +44,9 @@
} else { } else {
this.schema.mock = this.mock; this.schema.mock = this.mock;
} }
if (this.schema.type === 'object') {
this.$delete(this.schema, 'mock')
}
}, },
mounted() { mounted() {
}, },