JSON模式-递归模式定义 [英] JSON Schema - Recursive Schema Definition

查看:93
本文介绍了JSON模式-递归模式定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON模式

{
    'description': 'TPNode',
    'type': 'object',
    'id': 'tp_node',
    'properties': {
        'selector': {
            'type': 'string',
            'required': true
        }, 
        'attributes': {
            'type': 'array',
            'items': {
                'name': 'string',
                'value': 'string'
            }
        },
        'children': {
            'type': 'array',
            'items': {
                'type': 'object',
                '$ref': '#'
            }
        },
        'events': {
            'type': 'array',
            'items': { 
                'type': 'object',
                'properties': {
                    'type': {
                        'type': 'string'
                    },
                    'handler': {
                        'type': 'object'
                    },
                    'dependencies': {
                        'type': 'array',
                        'items': {
                            'type': 'string'
                        }
                     }
                 }
            }
        }
    }
}

我想在children属性中表达的是它是具有相同精确模式的对象数组.这是描述它的正确方法吗?

What I'm trying to express in the children property is that it's an array of objects with the same exact schema. Is this the correct way to describe it?

推荐答案

使用您需要引用的架构的id

Use the id of the schema you need to reference

'$ref': 'tp_node'

请参阅此处: http://json-schema.org/latest/json-schema-core.html#anchor30

这篇关于JSON模式-递归模式定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆