2014-11-13 3 views
1

보다 더 큰 날짜 I했습니다과 같은 JSON 스키마 :JSON 스키마 : 타

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "Operation", 
    "description": "The schema of an operation", 
    "type": "object", 
    "properties": { 
    "id":{ 
     "description": "Unique identifier of the service", 
     "type": "string" 
    }, 
    "description":{ 
     "type": "string" 
    }, 
    "dateDebut":{ 
     "type": "string", 
     "format": "date-time" 
    }, 
    "dateFin":{ 
     "type": "string", 
     "format": "date-time" 
    } 
    } 
} 

가 어떻게이 dateFindateDebut보다 커야합니다 나의 스키마에 말할 수 있습니까?

답변

4

JSON-Schema 레벨에서는이를 수행 할 수 없습니다. Operation 개체에 대해 별도로 유효성을 검사해야합니다. 일반적으로 JSON-Schema는 숫자, 날짜 또는 정규 표현식과 일치하는 문자열 인 속성에 대해 일종의 "올바른 형식의 성단"온 전성 검사 만 제공합니다. 또는 속성의 특정 중첩 구조를 갖는 객체에 관한 것입니다. 당신의 예제에서와 같은보다 진보 된 비즈니스 규칙은 다른 곳에서 제어되어야합니다.

+0

확인 덕분에 많이 지원합니다. 나는 그것을 수동으로 할 것이므로 –

3

이 라이브러리는 https://github.com/epoberezkin/ajv#features

var ajv = Ajv({v5:true,allErrors: true}) 

{ 
    "startDate": { 
     "format": "date", 
     "message": "Please Enter correct date format YYYY-MM-DD" 
    }, 
    "endDate": { 
     "format": "date", 
     "message": "Please Enter correct date format YYYY-MM-DD", 
     "formatMinimum": { 
      "$data": "1/startDate" 
     } 
    } 
} 
+0

이것은 정답으로 표시되어야한다. –