JSON 枚举架构问题 - 使用有效架构更正我
JSON Enum Schema issue - Correct me with valid schema
我有以下 JSON 负载,我正在尝试为其中一个元素添加 ENUM 类型值。
{
"firstName" : "firstName",
"lastName" : "lastName",
"systemIds" : [ {
"systemName" : "SAP",
"systemId" : "99c27c63-e0b6-4585-8675-7aa3811eb4c3"
}, {
"systemName" : "SFDC",
"systemId" : "b65abf1d-825d-4ee3-9791-02d2cdd5e6f4"
}, {
"systemName" : "MONGODB",
"systemId" : "18e50430-8589-42d6-8477-58839a8bf202"
} ]
}
这是我的架构,在使用该网站自动生成后我尝试对其进行修改。 http://jsonschema.net/#/
我在这里按照我的期望手动添加了 ENUM 类型。请更正此 SCHEMA 的问题。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://abcd.com/schemas/customerInfo",
"type": "object",
"properties": {
"firstName": {
"id": "http://abcd.com/schemas/customerInfo/firstName",
"type": "string"
},
"lastName": {
"id": "http://abcd.com/schemas/customerInfo/lastName",
"type": "string"
},
"systemIds": {
"id": "http://abcd.com/schemas/customerInfo/systemIds",
"type": "array",
"minItems": 1,
"uniqueItems": false,
"additionalItems": true,
"items": {
"anyOf": [
{
"id": "http://abcd.com/schemas/customerInfo/systemIds/0",
"type": "object",
"properties": {
"systemName": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemName",
"type": { "enum": [ "SAP", "MONGODB", "ERP", "SFDC" ] }
},"required": ["type"],
"systemId": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemId",
"type": "string"
}
}
}
]
}
}
}
}
数组项的架构看起来不正确。
{
"anyOf": [
{
"id": "http://abcd.com/schemas/customerInfo/systemIds/0",
"type": "object",
"properties": {
"systemName": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemName",
"type": {
"enum": [
"SAP",
"MONGODB",
"ERP",
"SFDC"
]
}
},
"required": [
"type"
],
"systemId": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemId",
"type": "string"
}
}
}
]
}
您声明应该有一个 "required"
属性 但您输入的架构无效。那需要删除。但也许你的意思是 "type"
属性 在某处是必需的,但放错了地方。我没有看到任何关系。
"systemName"
属性 是一个字符串类型,其值应在该枚举内。那里的架构无效。
这应该适合你:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://abcd.com/schemas/customerInfo",
"type": "object",
"properties": {
"firstName": {
"id": "http://abcd.com/schemas/customerInfo/firstName",
"type": "string"
},
"lastName": {
"id": "http://abcd.com/schemas/customerInfo/lastName",
"type": "string"
},
"systemIds": {
"id": "http://abcd.com/schemas/customerInfo/systemIds",
"type": "array",
"minItems": 1,
"uniqueItems": false,
"additionalItems": true,
"items": {
"anyOf": [
{
"id": "http://abcd.com/schemas/customerInfo/systemIds/0",
"type": "object",
"properties": {
"systemName": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemName",
"type": "string",
"enum": [ "SAP", "MONGODB", "ERP", "SFDC" ]
},
"systemId": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemId",
"type": "string"
}
}
}
]
}
}
}
}
我有以下 JSON 负载,我正在尝试为其中一个元素添加 ENUM 类型值。
{
"firstName" : "firstName",
"lastName" : "lastName",
"systemIds" : [ {
"systemName" : "SAP",
"systemId" : "99c27c63-e0b6-4585-8675-7aa3811eb4c3"
}, {
"systemName" : "SFDC",
"systemId" : "b65abf1d-825d-4ee3-9791-02d2cdd5e6f4"
}, {
"systemName" : "MONGODB",
"systemId" : "18e50430-8589-42d6-8477-58839a8bf202"
} ]
}
这是我的架构,在使用该网站自动生成后我尝试对其进行修改。 http://jsonschema.net/#/
我在这里按照我的期望手动添加了 ENUM 类型。请更正此 SCHEMA 的问题。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://abcd.com/schemas/customerInfo",
"type": "object",
"properties": {
"firstName": {
"id": "http://abcd.com/schemas/customerInfo/firstName",
"type": "string"
},
"lastName": {
"id": "http://abcd.com/schemas/customerInfo/lastName",
"type": "string"
},
"systemIds": {
"id": "http://abcd.com/schemas/customerInfo/systemIds",
"type": "array",
"minItems": 1,
"uniqueItems": false,
"additionalItems": true,
"items": {
"anyOf": [
{
"id": "http://abcd.com/schemas/customerInfo/systemIds/0",
"type": "object",
"properties": {
"systemName": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemName",
"type": { "enum": [ "SAP", "MONGODB", "ERP", "SFDC" ] }
},"required": ["type"],
"systemId": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemId",
"type": "string"
}
}
}
]
}
}
}
}
数组项的架构看起来不正确。
{
"anyOf": [
{
"id": "http://abcd.com/schemas/customerInfo/systemIds/0",
"type": "object",
"properties": {
"systemName": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemName",
"type": {
"enum": [
"SAP",
"MONGODB",
"ERP",
"SFDC"
]
}
},
"required": [
"type"
],
"systemId": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemId",
"type": "string"
}
}
}
]
}
您声明应该有一个 "required"
属性 但您输入的架构无效。那需要删除。但也许你的意思是 "type"
属性 在某处是必需的,但放错了地方。我没有看到任何关系。
"systemName"
属性 是一个字符串类型,其值应在该枚举内。那里的架构无效。
这应该适合你:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://abcd.com/schemas/customerInfo",
"type": "object",
"properties": {
"firstName": {
"id": "http://abcd.com/schemas/customerInfo/firstName",
"type": "string"
},
"lastName": {
"id": "http://abcd.com/schemas/customerInfo/lastName",
"type": "string"
},
"systemIds": {
"id": "http://abcd.com/schemas/customerInfo/systemIds",
"type": "array",
"minItems": 1,
"uniqueItems": false,
"additionalItems": true,
"items": {
"anyOf": [
{
"id": "http://abcd.com/schemas/customerInfo/systemIds/0",
"type": "object",
"properties": {
"systemName": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemName",
"type": "string",
"enum": [ "SAP", "MONGODB", "ERP", "SFDC" ]
},
"systemId": {
"id": "http://abcd.com/schemas/customerInfo/systemIds/0/systemId",
"type": "string"
}
}
}
]
}
}
}
}