Files
yapi/test/common/mergeJsonSchema.test.js
2024-03-01 20:28:14 +08:00

130 lines
2.2 KiB
JavaScript

import test from 'ava';
import mergeJsonSchema from '../../common/mergeJsonSchema';
test('base', t=>{
let schema1 = {
type: 'string',
default: 'xxx'
}
let schema2 = {
type: 'string',
format: 'email'
}
let result = mergeJsonSchema(schema1, schema2)
t.deepEqual(result, {
type:'string',
default: 'xxx',
format: 'email'
})
})
test('object', t=>{
let schema1 = {
"type": "object",
"title": "empty object",
"xxx": 1,
"properties": {
"field_1": {
"type": "string",
"format": "email"
}
}
}
let schema2 = {
"type": "object",
"title": "empty object",
"properties": {
"field_1": {
"type": "string",
"description": "dd"
}
}
}
let result = mergeJsonSchema(schema1, schema2)
t.deepEqual(result, {
"type": "object",
"title": "empty object",
"xxx": 1,
"properties": {
"field_1": {
"type": "string",
"format": "email",
"description": "dd"
}
}
})
})
test('array', t=>{
let schema1 = {
"type": "object",
"title": "empty object",
"properties": {
"field_1": {
"type": "array",
"tt":1,
"items": {
"type": "object",
"xxx": "2",
"properties": {
"field_3": {
"format": 'ttt',
"type": "string"
}
}
}
}
}
}
let schema2 = {
"type": "object",
"title": "empty object",
"properties": {
"field_1": {
"type": "array",
"items": {
"type": "object",
"properties": {
"field_3": {
"type": "string",
"enum": [1,2]
}
}
}
}
}
}
let result = mergeJsonSchema(schema1, schema2)
t.deepEqual(result, {
"type": "object",
"title": "empty object",
"properties": {
"field_1": {
"type": "array",
"tt":1,
"items": {
"type": "object",
"xxx": "2",
"properties": {
"field_3": {
"format": 'ttt',
"type": "string",
"enum": [1,2]
}
}
}
}
}
})
})