2017-11-22 7 views
0

JSON 스키마 유효성 확인에 대한 도움말은 샘플 JSON 및 스키마입니다. "ppd"스키마 규칙을 구체적으로 지정하는 방법을 알아 내려고하고 있습니다. "cfg"는 String, String의 맵이며 Enum 정의에 따라이 맵에서 키와 값의 항목을 추가로 제한해야합니다. 즉, "inputDateTimeFormat" 유효한 날짜 시간 형식이므로 key가 "inputDateTimeFormat"이면 인코딩해야하며 허용 된 값은 날짜 시간 형식과 일치하는 패턴이고 키가 "valuemapping"이면 허용되는 값은 패턴 일치 k = v (아래 예)입니다.열거 형 제약 조건이있는 문자열 맵을 사용하는 JSON 스키마 유효성 검사

이 방법을 제안 해주세요.

JSON 샘플 -

{ 
    "sm": [ 
    { 
     "mid": "id-1", 
     "ppd": [ 
     { 
      "name": "cc-1", 
      "cfg": { 
      "columns": "v-1", 
      "valueMapping": "B=01;S=02" 
      } 
     }, 
     { 
      "name": "cc-2", 
      "cfg": { 
      "columns": "v-2", 
      "inputDateTimeFormat": "ddMMMyyyy_HH:mm:ss.SSSSSS", 
      "outputDateTimeFormat": "yyyy-MM-dd'T'HH:mm:Ss.SSSZ" 
      } 
     }, 
     { 
      "name": "cc-3", 
      "cfg": { 
      "columns": "v-3;v-4", 
      "markers": "d=01" 
      } 
     } 
     ] 
    } 
    ] 
} 

JSON 스키마 : 스키마가 몇 가지 문제를 포함하여

{ 
    "type": "object", 
    "$schema": "http://json-schema.org/draft-06/schema", 
    "id": "source-mappings-schema", 
    "required": true, 
    "properties": { 
    "sm": { 
     "type": "array", 
     "id": "source-mappings-schema/sm", 
     "required": true, 
     "items": { 
     "type": "object", 
     "id": "source-mappings-schema/sm/0", 
     "required": true, 
     "properties": { 
      "mappingId": { 
      "type": "string", 
      "id": "source-mappings-schema/sm/0/mappingId", 
      "required": true 
      }, 
      "ppd": { 
      "type": "array", 
      "id": "source-mappings-schema/sm/0/ppd", 
      "required": true, 
      "items": { 
       "type": "object", 
       "id": "source-mappings-schema/sm/0/ppd/0", 
       "required": true, 
       "properties": { 
       "name": { 
        "type": "string", 
        "id": "source-mappings-schema/sm/0/ppd/0/name", 
        "required": true 
       }, 
       "cfg": { 
        "type": "array", 
        "id": "source-mappings-schema/sm/0/ppd/0/cfg", 
        "required": true, 
        "items": { 
        "type": "string" 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

답변

0

가 시작합니다. 당신이 적용 할 필요가 있으므로

은 $ 스키마 태그가 잘못, 그것은

"$schema": "http://json-schema.org/draft-06/schema#", 

'필요'속성은 필수 속성 이름 (안 부울)의 배열로되어 있어야한다 위 수준에서.

마지막으로 cfg의 유효성 검사. 'additionalProperties'에 대한 스키마를 지정하면 지정되지 않은 모든 키 값에 대한 유효성 검사 규칙을 제공 할 수 있습니다 (문자열지도라고 했으므로 문자열로 설정했지만 최대 길이 등 다른 규칙을 추가 할 수도 있음) . 당신이 알고있는 키에 대해 유효성 검사 규칙을 적용하여 각각의 속성을 추가 할 수 있습니다 (내가 추가 한 규칙이 개념을 증명하고 사용하기 위해 조정해야 함).

enter image description here

     "cfg": { 
           "type": "object", 
           "additionalProperties": { 
            "type": "string" 
           }, 
           "properties": { 
            "inputDateTimeFormat": { 
             "type": "string", 
             "format": "date-time" 
            }, 
            "valuemapping": { 
             "type": "string", 
             "pattern": "[a-z]\\=[a-z]" 
            } 
           } 
          }