1tree-schema 中文文档教程
1tree-schema
将 JSON 模式与 1tree 实例相互转换
const SchemaTree = require( '1tree-schema' )
const jsonSchema = require( './test.schema.json' )
const tree = SchemaTree( jsonSchema )
const integerNodes = tree.findAll( n => n.nodeType() === 'integer' )
integerNodes.forEach( n => {
const value = n.value()
value.minimum = 1
n.value( value )
})
const newSchema = tree.toSchema()
console.log( JSON.stringify( newSchema, null, 2 ) )
1tree-schema
Converts JSON schema to and from 1tree instances
const SchemaTree = require( '1tree-schema' )
const jsonSchema = require( './test.schema.json' )
const tree = SchemaTree( jsonSchema )
const integerNodes = tree.findAll( n => n.nodeType() === 'integer' )
integerNodes.forEach( n => {
const value = n.value()
value.minimum = 1
n.value( value )
})
const newSchema = tree.toSchema()
console.log( JSON.stringify( newSchema, null, 2 ) )