标签: jsonschema

JSON模式中"描述"字段的用途是什么?

我不确定JSON Schema"description"字段的用途是什么.该字段是否可作为评论的空间?该字段是否作为ID?

{
    "id": "http://www.noodle.org/entry-schema#",
    "schema": "http://json-schema.org/draft-04/schema#",
    "description": "schema for online courses",
    "type": "object",
    "properties": {
        "institution": {
            "type": "object",
           "$ref" : "#/definitions/institution" 
        },
        "person": {
            "type": "object",
            "items": {
                "type": "object",
                "$ref": "#/definitions/person"
            }   
    "definitions": {        
        "institution": {
            "description": "University",
            "type": "object",
            "properties": {
                "name":{"type":"string"},
                "url":{
                    "format": "uri",
                    "type": "string"
                },
                "descriptionofinstitution":{"type":"string"},
                "location": {
                    "description": "location",
                "type": "string",
                "required": true
                }
        }
Run Code Online (Sandbox Code Playgroud)

}

json jsonschema

2
推荐指数
2
解决办法
2040
查看次数

在json模式中支持std :: map <std :: string,T>

是否有标准方法将属性指定为字符串或由字符串键控的映射,并在模式中的其他位置指定值类型T?

例如,假设您要为用户最喜欢的电影建模,其中键类型是电影的名称,值类型是关于电影的一些属性集(年份,预算,总收入等)

我想你可以首先将MovieDataPair建模为具有name属性的类型和包含所需属性的value属性.然后地图就是那些数组.但是,那么你需要一个特殊的唯一约束来确保任何电影名称只出现一次.

是否有json架构中的某些东西支持这个,或者用于它的标准模式?如果没有在json架构中内置支持,那么其他架构解决方案呢?

json jsonschema

2
推荐指数
1
解决办法
2895
查看次数

使用JSON.Net反序列化JSON模式

我想使用JSON.Net反序列化此架构.

{ 
  "color" : { 
    "type" : "String", 
    "description" : "What color do you want your taco", 
    "required" : false, 
    "default" : "Green", 
    "options" : [ "Green", "Blue", "Red"]
  },
  "include_beans" : { 
    "type"  : "Boolean", 
    "description" : "Do you want beans on your taco", 
    "required" : false, 
    "default" : false 
  }, 
  "pounds"  : { 
    "type" : "Double", 
    "description" : "How  many pounds of meat do you want?", 
    "required"  : false, 
    "default" : 0.1 
  },  
  "count" : { 
    "type"  : …
Run Code Online (Sandbox Code Playgroud)

c# json json.net jsonschema deserialization

2
推荐指数
1
解决办法
1266
查看次数

Python jsonschema无法验证字符串枚举

因此,我正在尝试为一组轴约束定义一个架构。因此,我想将“ axis”元素的可能值限制为[“ x”,“ y”,“ z”]。

这是我当前的示例,它是输出。

JSON:

{
    "name_patterns": [
        {
            "regex": "block[_-]?([\\d]*)",
            "class": "block",
            "id_group": 1
        }
    ],

    "relationships": [
        {
            "src_class": "block",
            "dst_class": "block",
            "constraints": {
                "axis": "x"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

架构:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "name_patterns": {"type":  "array",
                          "items": { "$ref": "#/definitions/name_entry" } },
        "relationships": {"type":  "array",
                          "items": { "anyof": [ {"$ref": "#/definitions/relation"} ] } }
    },

    "definitions": {
        "name_entry": {
            "type": "object",
            "properties": {
                "regex": {"type": "string"},
                "class": {"type": "string"},
                "id_group": {"type": …
Run Code Online (Sandbox Code Playgroud)

python enums json jsonschema

2
推荐指数
1
解决办法
1677
查看次数

从json schema获取必填字段

我正在尝试针对模式测试许多json文档,并且我使用具有所有必需字段名称的对象来保持每个文件具有多少错误.

在任何python库中是否有一个函数创建一个样本对象,其中包含是否需要特定字段的布尔值.即从这个架构:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "type": {
            "type": "string"
        },
        "position": {
            "type": "array"
        },
        "content": {
            "type": "object"
        }
    },
    "additionalProperties": false,
    "required": [
        "type",
        "content"
    ]
}
Run Code Online (Sandbox Code Playgroud)

我需要得到类似的东西:

{
  "type" : True,
  "position" : False,
  "content" : True
}
Run Code Online (Sandbox Code Playgroud)

我也需要它来支持对定义的引用

python json jsonschema

2
推荐指数
1
解决办法
848
查看次数

公开API端点的JSON Schema?

在哪里以及如何公开API端点的架构是否有标准?

例如,假设以下API端点可用:

api/companies/

api/companies/{id}/employees/
Run Code Online (Sandbox Code Playgroud)

应该在哪里公开公司和员工资源的架构?

api/company-schema.jsonapi/employee-schema.json

api/schemas/company.jsonapi/schemas/employee.json

rest jsonschema json-api

2
推荐指数
1
解决办法
1037
查看次数

具有一个强制属性和至少另一个的json模式未检查

我在json中有此对象,我想使用json模式进行验证

"reference": {
    "lookup" : "opportunity",
    "shortreference": 93671,
    "guid": "4bb30c46-20ec-e511-9408-005056862bfb"
}
Run Code Online (Sandbox Code Playgroud)

lookup属性是强制性的,然后至少需要shortreferenceguid或两者兼有。

{
    "reference": {
      "type": "object",
      "description": "opportunity reference",
      "properties": {
        "lookup": {
          "enum": [
            "employee",
            "opportunity",
            "serviceline",
            "account"
          ]
        }
      },
      "anyOf": [
        {
          "properties": {
            "shortreference": {
              "type": "integer"
            },
            "guid": {
              "type": "string"
            }
          }
        }
      ],
      "required": [
        "lookup"
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

编辑 我使用以下架构解决了我的问题

{
    "reference": {
      "type": "object",
      "required": [
        "lookup"
      ],
      "properties": {
        "lookup": {
          "type": "string",
          "enum" …
Run Code Online (Sandbox Code Playgroud)

schema json jsonschema

2
推荐指数
1
解决办法
1234
查看次数

JSON模式中的多值枚举?

我有一个包含字符串的数组,例如:

[ 'foo', 'bar' ]
Run Code Online (Sandbox Code Playgroud)

可能的值是有限的。例如,有效值为foobarbaz

现在,当数组仅包含有效值,且不超过一个值,但可以具有任意数量的值时,该数组即为有效。

为有效数组的例子是[ 'foo' ][ 'foo', 'bar' ][ 'bar', 'baz' ]。无效阵列的例子是[][ 'foo', 'foo' ][ 'bar', 'something-else' ]

如何使用JSON模式进行验证?到目前为止,我已经弄清楚了array提供minItemsuniqueItems属性的类型。我还不能弄清楚的是:如何允许多个(但仅有效)值?我知道有enum,但这仅允许一个值,而不允许多个值。

有人可以帮忙吗?

PS:以防万一,我正在使用带有Node.js 的ajv模块来运行验证。

arrays validation json jsonschema

2
推荐指数
2
解决办法
2060
查看次数

JSON模式:为什么“常量”不能以与单值“枚举”相同的方式进行验证?

我有一个对象,提供一种资产版本的审核日志。它的几个属性(versionSource.metadataversionSource.files)是应根据两个架构之一验证的对象,具体取决于其架构之一的值。我开始在子方案中使用一个常量(在中oneOf,但那是说所有子方案都已验证(因此打破了oneOf多个已验证的方案。不过,将其更改为单值枚举是可行的)。

为什么验证有所不同?

这是原始架构:

{
   "$id": "https://example.com/schemas/asset-version.json",
   "title": "Audit log of asset versions",
   "$schema": "http://json-schema.org/draft-07/schema",

   "type": "object",
   "required": [
      "assetID",
      "version",
      "versionSource"
   ],

   "properties": {
      "assetID": {
         "type": "string"
      },
      "version": {
         "type": "integer",
         "minimum": 1
      },
      "versionSource": {
         "type": "object",
         "properties": {
            "metadata": {
               "type": "object",
               "oneOf": [
                  {
                     "properties": {
                        "sourceType": { "constant": "client" }
                     }
                  },
                  {
                     "$ref": "#/definitions/version-source-previous-version"
                  }
               ]
            },
            "files": {
               "type": "object",
               "oneOf": [
                  {
                     "properties": …
Run Code Online (Sandbox Code Playgroud)

json jsonschema

2
推荐指数
2
解决办法
3062
查看次数

为什么json-schema-faker会为所有内容返回拉丁语?

使用以下架构:

并且非常简单package.json,唯一的依赖关系是json-schema-faker(0.5.0.rc16),当我运行以下代码时,我看到输出显示在底部(示例运行)

jsf = require('json-schema-faker');
var schema = {
  "type": "object",
  "properties": {
    "users": {
        "type": "array",
        "minItems": 3,
        "maxItems": 5,
        "items": {
          "type": "object",
          "properties": {
              "id": {
                  "type": "integer",
                  "unique": true,
                 "minimum": 1
              },
              "firstName": {
                  "type": "string",
                  "faker": "name.findName"
              },
              "lastName": {
                  "type": "string",
                  "faker": "name.lastName"
              },
              "email": {
                "type": "string",
                "faker": "internet.email"
              }
          },
         "required": ["id", "firstName", "lastName", "email"]
        }
      }
    }, 
    "required": ["users"]  
};

var mylist = jsf.generate(schema);
console.log("mylist: ", mylist); …
Run Code Online (Sandbox Code Playgroud)

javascript jsonschema json-schema-faker

2
推荐指数
1
解决办法
452
查看次数