2014-11-01 47 views
1

我無法弄清楚如何正確設置超模式來使用json-schema-validator。我使用的是json-schema-validator的java版本,版本是2.2.5。如何使用json-schema-validator驗證JSON與超模式

我的模式是:

{ 
"$schema": "http://json-schema.org/draftv4/hyper-schema#", 
"title": "User object", 
"description": "A user representation", 
"type": "object", 
"properties": { 
    "email": { 
     "description": "The user's email address", 
     "format":"email", 
     "maxLength": 255 
    }, 
    "picture": { 
     "description": "The user's picture", 
     "type": "string", 
     "media": { 
      "binaryEncoding": "base64", 
      "type": "image/png" 
     } 
    } 
} 
} 

我的JSON對象是:

{"email":"[email protected]", 
"picture":null} 

現在,當我的模式加載到JsonSchemaFactory並打算開始驗證,我得到以下警告:

warning: the following keywords are unknown and will be ignored: [media] 
level: "warning" 
schema: {"loadingURI":"#","pointer":"/properties/picture"} 
domain: "syntax" 
ignored: ["media"] 

還有什麼要配置使用超模式besid在$模式字段?

回答

0

這是因爲你的$ schema是錯誤的!

它應該是http://json-schema.org/draft-04/hyper-schema#。有關衆所周知的URI列表,請參閱section 6 of the core specification

+0

好的。這工作。我現在可以解決超模式。但是,如果我提供了無效的base64字符串,例如「Abc der ...」作爲圖片值,那麼不會有任何錯誤報告。此外,「只讀」(readOnly)屬性也不被識別,並導致與上述相同的警告。 – 2014-11-04 15:34:08

+0

這裏有兩個單獨的問題:base64和readOnly。你會介意[開個問題](https://github.com/fge/json-schema-validator/issues)解決這兩個問題嗎?在該問題中,請粘貼您試圖驗證的完整模式和數據。 – fge 2014-11-04 15:40:11