对于为什么我的JSONSchema无法按预期验证我的数据,我感到非常困惑。
我在下面附加了我的JSONShema和示例日期。
该架构可以毫无问题地验证嵌套数据结构的第一层(组织),但是无法验证第二层(用户)及以下的用户。
有人能指出我做错了正确的方向吗?
非常感谢!
JSONSchema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://myorg/json/schemas/report-schedule.json",
"type": "array",
"items": {
"$ref": "#/definitions/Organisation"
},
"definitions": {
"Organisation": {
"type": "object",
"required": [
"organisationId",
"organisationName",
"users"
],
"properties": {
"organisationId": {
"type": "string",
"minLength": 1
},
"organisationName": {
"type": "string",
"minLength": 1
},
"users": {
"type": "array",
"items": {
"ref": "#/definitions/User"
}
}
}
},
"User": {
"type": "object",
"required": [
"name",
"email",
"reports"
],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"email": {
"type": "string",
"format": "email"
},
"reports": {
"type": "array",
"items": {
"ref": "#/definitions/Report"
}
}
}
},
"Report": {
"type": "object",
"required": [
"reportType",
"reportWeekEndDay",
"sendDay",
"sendHour",
"locations",
"widgets"
],
"properties": {
"reportType": {
"type": "string",
"enum": [
"org-weekly"
]
},
"reportWeekEndDay": {
"type": "integer",
"maximum": 6,
"minimum": 0
},
"sendDay": {
"type": "integer",
"maximum": 6,
"minimum": 0
},
"sendHour": {
"type": "integer",
"maximum": 23,
"minimum": 0
},
"locations": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
}
},
"widgets": {
"$ref": "#/definitions/Widgets"
}
}
},
"Widgets": {
"type": "array",
"title": "Widgets within a report",
"items": {
"$ref": "#/definitions/Widget"
}
},
"Widget": {
"type": "object",
"required": [
"widgetType",
"metrics",
"comparisonType"
],
"properties": {
"widgetType": {
"type": "string",
"enum": [
"table-individual-locations",
"table-all-locations"
]
},
"comparisonType": {
"type": "string",
"enum": [
"week-on-week",
"3-and-1-month-weekly-avg"
]
},
"metrics": {
"$ref": "#/definitions/Metrics"
}
}
},
"Metrics": {
"type": "array",
"title": "The Available Metrics",
"items": {
"oneOf": [
{
"$ref": "#/definitions/FootFallAndMovement"
},
{
"$ref": "#/definitions/Engagement"
},
{
"$ref": "#/definitions/Occupancy"
},
{
"$ref": "#/definitions/SalesDataTransactions"
},
{
"$ref": "#/definitions/SalesDataConversion"
}
]
}
},
"FootFallAndMovement": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "FootFallAndMovement"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff"
],
"properties": {
"excludeStaff": {
"type": "boolean"
}
}
}
}
},
"Engagement": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "Engagement"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff",
"contexts"
],
"properties": {
"additionalFilters": {
"type": "object",
"required": [
"ignoreLingerUnder"
],
"properties": {
"ignoreLingerUnder": {
"type": "integer",
"minimum": 1
}
}
},
"excludeStaff": {
"type": "boolean"
},
"contexts": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"const": "taxonomy"
},
"value": {
"type": "string",
"minLength": 1
}
}
}
}
}
}
},
"Occupancy": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "Occupancy"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff",
"contexts"
],
"properties": {
"excludeStaff": {
"type": "boolean"
},
"contexts": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"const": "taxonomy"
},
"value": {
"type": "string",
"minLength": 1
}
}
}
}
}
}
},
"SalesDataTransactions": {
"type": "object",
"required": [
"title",
"type",
"endpoint"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "SalesDataTransactions"
},
"endpoint": {
"type": "string",
"minLength": 1
}
}
},
"SalesDataConversion": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "SalesDataConversion"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff"
],
"properties": {
"excludeStaff": {
"type": "boolean"
}
}
}
}
}
}
}
示例数据
[
{
"organisationName": "a",
"organisationId": "a",
"users": [
{
"nameWITHERROR": "a"/*e.g. name should be required*/,
"email": "rob@test.com",
"reports": [
{
"reportType": "org-weekly1"/*e.g. this should be an enum*/,
"reportWeekEndDay": 6,
"sendDay": 6,
"sendHour": 6,
"locations": [
"abc",
"bcd"
],
"widgets": [
{
"widgetType": "table-all-locations",
"comparisonType": "3-and-1-month-weekly-avg",
"metrics": [
{
"title": "test",
"type": "FootFallAndMovement1"/*e.g. this enum should fail*/,
"endpoint": "/test",
"queryParams": {
"excludeStaff": true
}
},
{
"title": "test",
"type": "Engagement",
"endpoint": "/test",
"queryParams": {
"excludeStaff": true,
"contexts": {
"type": "taxonomy",
"value": "tests"
}
}
},
{
"title": "test",
"type": "Occupancy",
"endpoint": "/test",
"queryParams": {
"excludeStaff": true,
"contexts": {
"type": "taxonomy",
"value": "tests"
}
}
},
{
"title": "test",
"type": "SalesDataTransactions",
"endpoint": "/test"
},
{
"title": "test",
"type": "SalesDataConversion",
"endpoint": "/test",
"queryParams": {
"excludeStaff": true
}
}
]
}
]
}
]
}
]
}
]
答案 0 :(得分:1)
在JSONBuddy中打开JSON模式,立即向我显示您已在/ definitions / Organisation / properties / users / items / ref中使用“ ref”。由于没有找到定义,因此没有验证。