源碼地址: https://github.com/aydenuse/s...git
{ "title": "user", "description": "用戶數據模型", "type": "object", "properties": { "id": { "type": "string", "dValue": "" }, "name": { "type": "string", "dValue": "" }, "age": { "type": "integer", "dValue": 0 }, "tall": { "type": "number", "dVallue": 0, "minimum": "1.40", "maximum": "3.00" }, "status": { "type": "integer", "dValue": 0, "enumValue": [0, 1] }, "tag": { "type": "array", "dValue": [] }, "students": { "type": "array", "dValue": [], "itemType": "object", "properties": { "name": { "type": "string", "dValue": "" } }, "required": ["name"] }, "music": { "type": "object", "dValue": {}, "properties": { "id": { "type": "string", "dValue": "" }, "duration": { "type": "number", "dValue": 0 } }, "required": ["id", "duration"] } }, "required": ["id", "name", "age", "status", "music", "tag", "students", "tall"] }
'use strict' // 模擬業務數據 const data = { id: '5gdv4r4sdadwqjdhhf43546', name: '我是王曉武', age: '23', tag: ['man', 'teacher', 'sport', { id: 1 }], _v: '123123', music: { }, students: [ { name: 'ayden' } ], tall: 1.89 } const schemaParser = require('./schema-parser') const schema = new schemaParser() schema.init() const result = schema.build({ data: data, title: 'user' }) console.log(result)
// { id: '5gdv4r4sdadwqjdhhf43546', name: '我是王曉武', age: 23, status: 0, music: { id: '', duration: 0 }, tag: [ 'man', 'teacher', 'sport', { id: 1 } ], students: [ { name: 'ayden' } ], tall: 1.89 }