• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

JSON模式oneOf用于具有固定值的数组

用户头像
it1352
帮助2

问题说明

我想为oneOf指定多个值,并定义了以下可成功验证的架构( http://json-schema-validator.herokuapp.com/).请注意,在此示例中,oneOf下故意只有一个值.

I want to specify multiple values for oneOf and have defined the below schema that validates successfully (http://json-schema-validator.herokuapp.com/). Note there is deliberately only one value under oneOf in this example.

{
    "id": "test-schema",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "test schema",

    "type": "object",
    "properties": {

        "alpha": {

            "type": "object",
            "properties": {

                "beta": {

                    "oneOf": [
                        {
                            "type": "object",
                            "properties": {

                                "ObjA": {

                                    "type": "object",
                                    "properties": {

                                        "a": {

                                            "type": "array",
                                            "items": {

                                                "type": "number",
                                                "default": [90, 95],
                                                "additionalProperties": false
                                            },
                                            "additionalProperties": false
                                        },

                                        "b": {

                                            "type": "array",
                                            "items": {

                                                "type": "number",
                                                "default": [4, 8],
                                                "additionalProperties": false
                                            },
                                            "additionalProperties": false
                                        },

                                        "c": {

                                            "type": "array",
                                            "items": {

                                                "type": "number",
                                                "default": [0.2, 0.6],
                                                "additionalProperties": false
                                            },
                                            "additionalProperties": false
                                        }
                                    },                                    
                                    "additionalProperties": false
                                }
                            }, 
                            "additionalProperties": false
                        }
                    ]
                }
            },         
            "additionalProperties": false
        }
    },
    "additionalProperties": false
}    

Q1:我正在使用default来指定初始数组值,但实际上是希望将它们固定并不允许任何其他值.我该如何实现?

Q1: I am using default to specify the initial array value but really want these to be fixed and disallow any other values. How can I achieve this?

在此处回答如何指定哪个一个JSON对象应该使用的项目?.

Q2:我想在针对此架构进行验证的JSON文件中指定为beta分配ObjA,我该如何指定呢?

Q2: I want to specify that beta be assigned ObjA in a JSON file that validates against this schema, how do I specify this?

在此处回答如何指定一个JSON对象应该使用的项目?.

正确答案

#1

在这里回答查看全文

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhbfgkcg
系列文章
更多 icon
同类精品
更多 icon
继续加载