没有名称的对象的JSON模式 [英] JSON Schema for objects without names

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

问题描述

我想编写验证对象列表的架构的一部分,其中列表中的对象没有名称:

I want to write part of a schema that validates a list of objects, where the objects in the list don't have a name:

"some list": [
    {
        "thing 1": "foo",
        "thing 2": 100
    },
    {
        "thing 1": "foo",
        "thing 2": 100
    },
    {
        "thing 1": "foo",
        "thing 2": 100
    },
]

我有一个工作模式,该模式具有要删除的额外键名,标记为I WANT TO GET RID OF THIS NAME.我想您可能会认为它没有该对象的属性名称.

I have a working schema that has the extra key name that I want to get rid of, labelled I WANT TO GET RID OF THIS NAME. I guess you could think of it as not having a property name for that object.

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "id": "v2",
    "properties": {
        "some list": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "I WANT TO GET RID OF THIS NAME": {
                        "type": "object",
                        "properties": {
                            "thing 1": {
                                "type": "string",
                                "description": "a string"
                            },
                            "thing 2": {
                                "type": "integer",
                                "minimum": 0,
                                "description": "Default time to expose a single image layer for."
                            }
                        },
                        "additionalProperties": false
                    },
                    "additionalProperties": false
                }
            }
        }
    }
}

我不能仅仅摆脱名称,因为架构规范期望它,但是我也想不出如何告诉那些对象没有名称.我正在使用jsonschema Draft7Validator

I can't just git rid of the name because the schema spec expects it, but I also can't figure out how to tell it those objects don't have a name. I am running this example with Python 3.7 using jsonschema Draft7Validator

推荐答案

您正确地摆脱了该属性-它指的是错误的嵌套级别.架构应如下所示:

you are correct to get rid of that property - it is referring to the wrong level of nesting. the schema should look like:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "v2",
  "properties": {
    "some list": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "thing 1": {
            "type": "string",
            "description": "a string"
          },
          "thing 2": {
            "type": "integer",
            "minimum": 0,
            "description": "Default time to expose a single image layer for."
          }
        },
        "additionalProperties": false
      }
    }
  }
}

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

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