【发布时间】:2015-12-30 03:50:29
【问题描述】:
我有以下 JSON 模式:
架构 A:
{
"$schema": "http://json-schema.org/draft-04/hyper-schema#",
"title": "A",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"entityBId": {
"type": "string"
}
},
"required": [
"name",
"entityBId"
],
"links": [
{
"rel": "B",
"href": "myapi/EntityB?id={entityBId}"
}
]
}
架构 B:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "B",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"name"
]
}
我正在尝试确定是否有一种方法可以运行基于 JSON 模式的完整性检查以及外部链接/引用。 例如:当我收到一个 entityBId = 1 的对象 A 时,我想获取在链接 href 中声明的端点中运行 GET 的该实体 B 并检查是否存在有效对象从收到的 id。 它将像深度验证一样运行,并且在没有定义数据库架构的场景中很有用。
【问题讨论】:
-
不,json 不是 xml。如果你想验证,那么你必须定义一个函数——进行验证——并在你的代码中调用该函数
标签: json jsonschema json-schema-validator