2017-11-10 18 views
5

Tôi đã tạo lược đồ JSON theo thông số kỹ thuật dự thảo v3. Giản đồ trông giống như sau:

{ 
"$schema": "http://json-schema.org/draft-03/schema#", 
"additionalProperties": false, 
"type": "object", 
"properties": { 
    "ExecutionPlanList": { 
     "type": "array", 
     "items": [{ 
      "type": "object", 
      "properties": { 
       "model": { 
        "required": true, 
        "properties": { 
         "featureList": { 
          "required": true, 
          "items": { 
           "properties": { 
            "featureName": { 
             "type": ["string", "null"] 
            }, 
            "featureType": { 
             "type": "string" 
            } 
           }, 
           "type": "object" 
          }, 
          "type": "array" 
         }, 
         "modelId": { 
          "required": true, 
          "type": "string" 
         } 
        }, 
        "type": "object" 
       }, 
       "cascadeSteps": { 
        "required": false, 
        "items": { 
         "properties": { 
          "binaryModel": { 
           "$ref": "#/properties/ExecutionPlanList/items/properties/model", 
           "required": true 
          }, 
          "threshold": { 
           "required": true, 
           "default": "0.0", 
           "maximum": 100.0, 
           "type": "number" 
          }, 
          "backupModel": { 
           "$ref": "#/properties/ExecutionPlanList/items/properties/model", 
           "required": true 
          } 
         } 
        }, 
        "type": "array" 
       }, 
       "marketplaceId": { 
        "required": true, 
        "type": "integer" 
       } 
      } 
     }] 
    } 
}, 
"required": true 
} 

Về cơ bản, executePlanList chứa danh sách mô hình và tầngTrước, mỗi tầng chứa hai mô hình có số. Vì vậy, tôi đang cố gắng tái sử dụng lược đồ cho mô hình trong cascadeStep, nhưng xác nhận (https://www.jsonschemavalidator.net/) là không với Could not resolve schema reference '#/properties/ExecutionPlanList/items/properties/model'.

Sẽ đánh giá cao bất kỳ gợi ý nào về sai sót của giản đồ này.

Trả lời

3

gì về việc thêm một 'định nghĩa' và tham khảo như thế này:

{ 
"$schema": "http://json-schema.org/draft-03/schema#", 
"additionalProperties": false, 
"type": "object", 
"definitions": { 
     "model": { 
      "required": true, 
      "properties": { 
       "featureList": { 
        "required": true, 
        "items": { 
         "properties": { 
          "featureName": { 
           "type": ["string", "null"] 
          }, 
          "featureType": { 
           "type": "string" 
          } 
         }, 
         "type": "object" 
        }, 
        "type": "array" 
       }, 
       "modelId": { 
        "required": true, 
        "type": "string" 
       } 
      }, 
      "type": "object" 
     } 
}, 
"properties": { 
    "ExecutionPlanList": { 
     "type": "array", 
     "items": [{ 
      "type": "object", 
      "properties": { 
       "model": { 
        "$ref" : "#/definitions/model" 
       }, 
       "cascadeSteps": { 
        "required": false, 
        "items": { 
         "properties": { 
          "binaryModel": { 
           "$ref" : "#/definitions/model", 
           "required": true 
          }, 
          "threshold": { 
           "required": true, 
           "default": "0.0", 
           "maximum": 100.0, 
           "type": "number" 
          }, 
          "backupModel": { 
           "$ref" : "#/definitions/model", 
           "required": true 
          } 
         } 
        }, 
        "type": "array" 
       }, 
       "marketplaceId": { 
        "required": true, 
        "type": "integer" 
       } 
      } 
     }] 
    } 
}, 
"required": true 
} 
4

Nó phải là '#/tài sản/ExecutionPlanList/mục/0/tài sản/mô hình'

Giản đồ xác nhận chỉ mục đầu tiên, bằng cách này.

+0

Cảm ơn. Bạn có thể xây dựng trên phần thứ hai "xác nhận chỉ mục đầu tiên" – Stormbringer

+0

Khi giá trị "mục" là một mảng, lược đồ chỉ áp dụng cho mục đầu tiên trong mảng. Đó là ok nếu nó được dự định, nhưng nó cũng là một sai lầm phổ biến ... – esp

+0

Ohh .. đó chắc chắn không phải là ý định của tôi. Vì v3 không hỗ trợ từ điển, cách được khuyến nghị để sử dụng lại các lược đồ ở đây là gì? – Stormbringer

Các vấn đề liên quan