json의 유효성을 검사하는 스키마가 있습니다.jsonschema - 정적 속성을 사용하는 동적 속성
특정 속성의 경우 특정 유형의 값이 필요합니다.
- "ATTR"속성이 "는"다음 "발"속성 "ATTR"속성이면
- 는 "x"는 그 다음 "발"은 재산권
- "부울"합니다 "정수"이어야 "ATTR"속성이 "B"의 경우, "발"속성은 ... 형식 "IPv4의"와 "문자열"
등해야
이를, 나는 oneOff로 정의 할 수 있습니다. 다른 모든 "attr"속성의 경우 특정 형식으로되어 있어야하며, "문자열"속성 인 "val"속성과 함께 일종의 캐치와 비슷합니다.
- "attr"이 패턴과 일치하면 "val"속성은 "string"이어야합니다.
이 작업을 수행 할 수 있습니다.
이것은 현재 내가 가지고있는 스키마입니다.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": {
"title": "name",
"type": "string"
},
"attribute": {
"title": "attributes",
"type": "object",
"$ref": "#/definitions/expr",
}
},
"definitions": {
"expr": {
"properties": {
"attr": {
"title": "attribute"
},
"val": {
"title": "val"
}
},
"required": ["val", "attr"],
"oneOf": [
{
"properties": {
"attr": {"enum": ["a","b"]},
"val": {"type": "integer"}
}
},
{
"properties": {
"attr": {"enum": ["x"]},
"val": {"type": "boolean"}
}
},
{
"properties": {
"attr": {"pattern": "^[-A-Za-z0-9_]*$", "maxLength": 255},
"val": {"type": "string"}
}
}
]
}
},
"additionalProperties": false,
"required": [
"name",
"attribute"
]
}
문제점은 값 유형을 제한하려고 시도하는 속성이며 catchall 형식과 일치합니다. 그래서 내가 정수 값을 기대하고, 그것은 문자열 값으로 전달됩니다. 예를 들어
:
는 아래의 JSON이 oneOff의 마지막 항목에 따라 oneOff
{
"name": "shouldpass",
"attribute": {
"attr": "a",
"val": 1
}
}
아래의 JSON이 통과 할의 첫 번째 항목에 따라 스키마를, 전달합니다.
{
"name": "shouldpass2",
"attribute": {
"attr": "h",
"val": "asd"
}
}
아래 JSON은 oneOff의 첫 번째 항목에 기초하여, 실패하지만 oneOff의 마지막 항목에 매칭되기 때문에 역시 전달된다.
{
"name": "shouldfail",
"attribute": {
"attr": "a",
"val": "string"
}
}
어떻게 해결할 수 있습니까?