2016-12-14 2 views
0

일부 입력의 유효성을 검사하기 위해 ajv 모듈을 사용하려고합니다. 정규 JSON 스키마로 작업하게 만들었지 만 여러 경로의 유효성을 검사하고 링크 데이터를 사용하여 문서를 작성하려고했지만 설정하는 방법이 혼란 스럽습니다.ajv로 JSON 하이퍼 스키마 확인

{ 
     "$schema": "http://json-schema.org/draft-04/hyper-schema#", 
     "title": "Questions", 
     "type": "object", 
     "definitions": { 
     "companyId": { 
      "type": "string", 
      "minLength": 3, 
      "maxLength": 20 
     } 
     }, 
     "links":[ 
     { 
      "title": "List", 
      "href": "/questions", 
      "method": "POST", 
      "rel": "self", 
      "schema": { 
      "properties": { 
       "companyId": { 
       "$ref": "#/definitions/companyId" 
       } 
      }, 
      "required": ["companyId"] 
      } 
     } 
     ] 
    } 

그리고 내 코드 :

const schema = require('./schemas/questions.json'); 
const hyperSchema = require('../schemas/hyper-schema.json'); 
const Ajv = require('ajv'); 

const ajv = new Ajv({ allErrors: true, v5: true }); 
ajv.addMetaSchema(hyperSchema, undefined, true); 

const validate = ajv.compile(schema); 
const valid = validate(input); 
console.log(valid) 

내 질문이 내 스키마를로드하면 어떻게 스키마를 연결하려면 어떤 AJV에 대해 유효성을 알 수 있습니까, 여기 내 스키마는 무엇입니까? 나는 유효성을 검사하기 위해 differnt 입력과 함께 여러 경로 (링크)를 가질 것이다.

또한 스키마가 올바르게 설정 되었습니까?

const ajv = new Ajv({ allErrors: true, removeAdditional: true, v5: true }); 
ajv.addMetaSchema(hyperSchema, undefined, true); 
ajv.addSchema(schema, 'questions.json'); 
const valid = ajv.validate({ $ref: 'questions.json#/links/0/schema' }, input); 
:

답변

0

경우 다른 사람이이 필요에

는,이 같은 JSON 포인터를 사용