예를 들어 파일 시스템 스키마는 파일 목록을 포함합니다. 스키마는 파일의 스펙, 하위 유형 "이미지"및 다른 하나의 "텍스트"로 구성됩니다.속성 값에서 스키마를 선택하도록 JSON 스키마 유효성 검사기를 지정하는 방법은 무엇입니까?
아래에는 기본 디렉토리 스키마가 있습니다. 디렉토리에는 파일의 하위 유형이어야하는 항목의 배열 인 특성 내용이 있습니다.
기본적으로 내가 찾고있는 것은 유효성 검사기에게 유효성이 검사되는 json 개체의 속성에서 "$ ref"값을 조회하도록 지시하는 방법입니다.
예 JSON :
{
"name":"A directory",
"content":[
{
"fileType":"http://x.y.z/fs-schema.json#definitions/image",
"name":"an-image.png",
"width":1024,
"height":800
}
{
"fileType":"http://x.y.z/fs-schema.json#definitions/text",
"name":"readme.txt",
"lineCount":101
}
{
"fileType":"http://x.y.z/extended-fs-schema-video.json",
"name":"demo.mp4",
"hd":true
}
]
}
"이미지"와 "텍스트"정의는 동일한 스키마에 포함되어 있지만 다른
{ "id": "http://x.y.z/fs-schema.json", "definitions": { "file": { "type": "object", "properties": { "name": { "type": "string" }, "fileType": { "type": "string", "format": "uri" } } }, "image": { "allOf": [ { "$ref": "#definitions/file" }, { "properties": { "width": { "type": "integer" }, "height": { "type": "integer"} } } ] }, "text": { "allOf": [ { "$ref": "#definitions/file" }, { "properties": { "lineCount": { "type": "integer"}}} ] } }, "type": "object", "properties": { "name": { "type": "string"}, "content": { "type": "array", "items": { "allOf": [ { "$ref": "#definitions/file" }, { *"$refFromProperty"*: "fileType" } // the magic thing ] } } } }
을 정의 할 수있는 "의사"스키마 참고
설명이 필요합니다. 디렉터리 데이터가 정의 될 때 (디자인 타임이 아닐 때) 정의 된 특정 속성을 fullfil하여 디렉터리의 모든 파일 항목을 적용하려고합니다. 맞습니까? – jruizaranguren
속성의 하위 유형에 대한 올바른 정의를 선택하고 싶습니다. fileType – redben