0
에 따라 값이 나는 장난감 3 종류를 정의하는 다음 JSON 스키마이 json GUI builder (github)와 함께 사용할 수있다 :JSON 스키마 : oneOf
{
"id": "http://some.site.somewhere/entry-schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "schema for toys in game",
"type": "object",
"required": [ "type" ],
"properties": {
"sawObj": {
"type": "object",
"oneOf": [
{ "$ref": "#/definitions/rect" },
{ "$ref": "#/definitions/circle" },
{ "$ref": "#/definitions/img" }
]
}
},
"definitions": {
"rect": {
"properties": {
"width": { "type": "integer" },
"height": { "type": "integer" },
"weight": { "type": "integer" }
},
"required": [ "width", "height", "weight" ],
"additionalProperties": false
},
"circle": {
"properties": {
"radius": { "type": "integer" },
"weight": { "type": "integer" }
},
"required": [ "radius", "weight" ],
"additionalProperties": false
},
"img": {
"properties": {
"path": { "type": "string" },
"width": { "type": "integer" },
"height": { "type": "integer" },
"weight": { "type": "integer" }
},
"required": [ "path", "width", "height", "weight" ],
"additionalProperties": false
}
}
}
내가 예를 들어 원 객체를 선택하는 경우 나는 출력을 얻을 :
{
"sawObj": {
"radius": 0,
"weight": 0
}
}
내가 항상 사용자에게 선택 유형을 반영하기 위해 제한 될 값 "유형"를 추가하고 싶다. 대신 다음과 같은 내용이 있습니다.
{
"sawObj": {
"type": "circle",
"radius": 0,
"weight": 0
}
}
여기서 유형은 oneOf 속성 섹션의 사용자 선택에 따라 자동으로 결정됩니다.
어떻게 json-schema로이 작업을 수행 할 수 있습니까?