fix(接口测试): 文档结构根保护处理防止解析错误
--bug=1009952 --user=赵勇 【接口测试】文档结构断言-跟随api定义,接口响应格式错误时会报错 https://www.tapd.cn/55049933/s/1098029
This commit is contained in:
parent
a3c6f213b6
commit
d3b810c062
|
@ -17,11 +17,11 @@
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="4">
|
<el-col :span="4">
|
||||||
<el-select v-model="pickValue.type" :disabled="disabledType" class="ms-col-type" @change="onChangeType" size="small">
|
<el-select v-model="pickValue.type" :disabled="disabledType" class="ms-col-type" @change="onChangeType" size="small">
|
||||||
<el-option :key="t" :value="t" :label="t" v-for="t in TYPE_NAME"/>
|
<el-option :key="t" :value="t" :label="t" v-for="t in types"/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="4">
|
<el-col :span="4">
|
||||||
<ms-mock :disabled="pickValue.type==='object' || pickValue.type==='array' || pickValue.type==='null'" :schema="pickValue"/>
|
<ms-mock :disabled="pickKey ==='root' || pickValue.type==='object' || pickValue.type==='array' || pickValue.type==='null'" :schema="pickValue"/>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="4">
|
<el-col :span="4">
|
||||||
<el-input v-model="pickValue.description" class="ms-col-title" :placeholder="$t('schema.description')" size="small"/>
|
<el-input v-model="pickValue.description" class="ms-col-title" :placeholder="$t('schema.description')" size="small"/>
|
||||||
|
@ -71,8 +71,8 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
<p class="tip">{{$t('schema.preview')}} </p>
|
<p class="tip">{{ $t('schema.preview') }} </p>
|
||||||
<pre style="width:100%">{{completeNodeValue}}</pre>
|
<pre style="width:100%">{{ completeNodeValue }}</pre>
|
||||||
|
|
||||||
<span slot="footer" class="dialog-footer">
|
<span slot="footer" class="dialog-footer">
|
||||||
<ms-dialog-footer
|
<ms-dialog-footer
|
||||||
|
@ -83,13 +83,13 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import {isNull} from './util'
|
import {isNull} from './util'
|
||||||
import {TYPE_NAME, TYPE} from './type/type'
|
import {TYPE_NAME, TYPE, TYPES} from './type/type'
|
||||||
import MsMock from './mock/MockComplete'
|
import MsMock from './mock/MockComplete'
|
||||||
import MsDialogFooter from '../../../components/MsDialogFooter'
|
import MsDialogFooter from '../../../components/MsDialogFooter'
|
||||||
import {getUUID} from "@/common/js/utils";
|
import {getUUID} from "@/common/js/utils";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'JsonSchemaEditor',
|
name: 'JsonSchemaEditor',
|
||||||
components: {MsMock, MsDialogFooter},
|
components: {MsMock, MsDialogFooter},
|
||||||
props: {
|
props: {
|
||||||
|
@ -149,6 +149,9 @@
|
||||||
advanced() {
|
advanced() {
|
||||||
return TYPE[this.pickValue.type]
|
return TYPE[this.pickValue.type]
|
||||||
},
|
},
|
||||||
|
types(){
|
||||||
|
return TYPES(this.pickKey);
|
||||||
|
},
|
||||||
advancedAttr() {
|
advancedAttr() {
|
||||||
return TYPE[this.pickValue.type].attr
|
return TYPE[this.pickValue.type].attr
|
||||||
},
|
},
|
||||||
|
@ -169,7 +172,6 @@
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
TYPE_NAME,
|
|
||||||
hidden: false,
|
hidden: false,
|
||||||
countAdd: 1,
|
countAdd: 1,
|
||||||
modalVisible: false,
|
modalVisible: false,
|
||||||
|
@ -195,9 +197,9 @@
|
||||||
this.$set(this.parent, 'properties', p)
|
this.$set(this.parent, 'properties', p)
|
||||||
},
|
},
|
||||||
onChangeType() {
|
onChangeType() {
|
||||||
if(this.parent && this.parent.type === 'array'){
|
if (this.parent && this.parent.type === 'array') {
|
||||||
this.$emit('changeAllItemsType',this.pickValue.type);
|
this.$emit('changeAllItemsType', this.pickValue.type);
|
||||||
}else{
|
} else {
|
||||||
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')
|
||||||
|
@ -207,8 +209,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeAllItemsType(changeType){
|
changeAllItemsType(changeType) {
|
||||||
if(this.isArray && this.pickValue.items && this.pickValue.items.length > 0){
|
if (this.isArray && this.pickValue.items && this.pickValue.items.length > 0) {
|
||||||
this.pickValue.items.forEach(item => {
|
this.pickValue.items.forEach(item => {
|
||||||
item.type = changeType;
|
item.type = changeType;
|
||||||
this.$delete(item, 'properties')
|
this.$delete(item, 'properties')
|
||||||
|
@ -254,14 +256,14 @@
|
||||||
const node = this.pickValue;
|
const node = this.pickValue;
|
||||||
if (this.isArray) {
|
if (this.isArray) {
|
||||||
let childObj = {type: 'string', mock: {mock: ""}}
|
let childObj = {type: 'string', mock: {mock: ""}}
|
||||||
if(node.items && node.items.length > 0){
|
if (node.items && node.items.length > 0) {
|
||||||
childObj.type = node.items[0].type;
|
childObj.type = node.items[0].type;
|
||||||
node.items.push(childObj);
|
node.items.push(childObj);
|
||||||
}else {
|
} else {
|
||||||
this.$set(this.pickValue, 'items', [childObj]);
|
this.$set(this.pickValue, 'items', [childObj]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
} else {
|
||||||
const name = this._joinName()
|
const name = this._joinName()
|
||||||
const type = 'string'
|
const type = 'string'
|
||||||
node.properties || this.$set(node, 'properties', {})
|
node.properties || this.$set(node, 'properties', {})
|
||||||
|
@ -280,7 +282,7 @@
|
||||||
this.customing = false
|
this.customing = false
|
||||||
},
|
},
|
||||||
removeNode() {
|
removeNode() {
|
||||||
if(this.parent.type && this.parent.type === 'object'){
|
if (this.parent.type && this.parent.type === 'object') {
|
||||||
const {properties, required} = this.parent
|
const {properties, required} = this.parent
|
||||||
this.$delete(properties, this.pickKey)
|
this.$delete(properties, this.pickKey)
|
||||||
if (required) {
|
if (required) {
|
||||||
|
@ -288,7 +290,7 @@
|
||||||
pos >= 0 && required.splice(pos, 1)
|
pos >= 0 && required.splice(pos, 1)
|
||||||
required.length === 0 && this.$delete(this.parent, 'required')
|
required.length === 0 && this.$delete(this.parent, 'required')
|
||||||
}
|
}
|
||||||
}else if(this.parent.type && this.parent.type === 'array'){
|
} else if (this.parent.type && this.parent.type === 'array') {
|
||||||
const {items, required} = this.parent
|
const {items, required} = this.parent
|
||||||
this.$delete(items, this.pickKey)
|
this.$delete(items, this.pickKey)
|
||||||
if (required) {
|
if (required) {
|
||||||
|
@ -326,67 +328,67 @@
|
||||||
this.$set(this.pickValue, item.key, item.value)
|
this.$set(this.pickValue, item.key, item.value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parentReloadItems(){
|
parentReloadItems() {
|
||||||
this.$emit("reloadItems");
|
this.$emit("reloadItems");
|
||||||
},
|
},
|
||||||
reloadItems(){
|
reloadItems() {
|
||||||
this.reloadItemOver = false;
|
this.reloadItemOver = false;
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.reloadItemOver = true;
|
this.reloadItemOver = true;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.json-schema-editor .row {
|
.json-schema-editor .row {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 12px;
|
margin: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .ms-col-name {
|
.json-schema-editor .row .ms-col-name {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .ms-col-name .ms-col-name-c {
|
.json-schema-editor .row .ms-col-name .ms-col-name-c {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .ms-col-name .ms-col-name-required {
|
.json-schema-editor .row .ms-col-name .ms-col-name-required {
|
||||||
flex: 0 0 30px;
|
flex: 0 0 30px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .ms-col-type {
|
.json-schema-editor .row .ms-col-type {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .ms-col-setting {
|
.json-schema-editor .row .ms-col-setting {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .setting-icon {
|
.json-schema-editor .row .setting-icon {
|
||||||
color: rgba(0, 0, 0, 0.45);
|
color: rgba(0, 0, 0, 0.45);
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .plus-icon {
|
.json-schema-editor .row .plus-icon {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor .row .close-icon {
|
.json-schema-editor .row .close-icon {
|
||||||
color: #888;
|
color: #888;
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor-advanced-modal {
|
.json-schema-editor-advanced-modal {
|
||||||
color: rgba(0, 0, 0, 0.65);
|
color: rgba(0, 0, 0, 0.65);
|
||||||
min-width: 600px;
|
min-width: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor-advanced-modal pre {
|
.json-schema-editor-advanced-modal pre {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
@ -394,29 +396,29 @@
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor-advanced-modal h3 {
|
.json-schema-editor-advanced-modal h3 {
|
||||||
display: block;
|
display: block;
|
||||||
border-left: 3px solid #1890ff;
|
border-left: 3px solid #1890ff;
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor-advanced-modal .ms-advanced-search-form {
|
.json-schema-editor-advanced-modal .ms-advanced-search-form {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.json-schema-editor-advanced-modal .ms-advanced-search-form .ms-form-item .ms-form-item-control-wrapper {
|
.json-schema-editor-advanced-modal .ms-advanced-search-form .ms-form-item .ms-form-item-control-wrapper {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.col-item-setting {
|
.col-item-setting {
|
||||||
padding-top: 8px;
|
padding-top: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ms-transform {
|
.ms-transform {
|
||||||
transform: rotate(-180deg);
|
transform: rotate(-180deg);
|
||||||
transition: 0ms;
|
transition: 0ms;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -4,7 +4,9 @@ import _array from './array'
|
||||||
import _boolean from './boolean'
|
import _boolean from './boolean'
|
||||||
import _integer from './integer'
|
import _integer from './integer'
|
||||||
import _number from './number'
|
import _number from './number'
|
||||||
const TYPE_NAME = ['string', 'number', 'integer','object', 'array', 'boolean']
|
import {LicenseKey} from "@/common/js/constants";
|
||||||
|
|
||||||
|
const TYPE_NAME = ['string', 'number', 'integer', 'object', 'array', 'boolean']
|
||||||
|
|
||||||
const TYPE = {
|
const TYPE = {
|
||||||
'object': _object,
|
'object': _object,
|
||||||
|
@ -14,4 +16,11 @@ const TYPE = {
|
||||||
'integer': _integer,
|
'integer': _integer,
|
||||||
'number': _number
|
'number': _number
|
||||||
}
|
}
|
||||||
export {TYPE ,TYPE_NAME}
|
export {TYPE, TYPE_NAME}
|
||||||
|
|
||||||
|
export function TYPES(key) {
|
||||||
|
if (key && key === 'root') {
|
||||||
|
return ['object', 'array'];
|
||||||
|
}
|
||||||
|
return TYPE_NAME;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue