2016-08-03 22 views
1

考慮這個例子:如何在JSON模式中使用allOf的additionalProperties?

"allOf": [ 
    {"$ref": "test-address-prefix-types-base.json#"}, 
    { 
     "properties": {}, "additionalProperties" : false 
    } 
]} 

當我確認這與Java架構驗證,我得到錯誤說:

"keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"attributes\",\"type\"]"}] 

但同樣的JSON對象驗證對基礎架構(測試地址前綴-types-base)通過沒有錯誤。

被引用的模式(基本一)沒有設置additionalProperties。

這是JSON消息,我使用:

 String message = "{\"data\":{\"attributes\":{" + 
      "\"notation\": \"A\"," + 
      "\"prefixType\": \"A\"}" + 
      ",\"type\":\"test-address-prefix-types\"}}"; 

我錯過了在架構什麼? 感謝

回答

2

你的架構可以擴展這種方式:

allof:它必須驗證independently對兩個模式:

  • 首先一個具有任意性通過ref聯繫。
  • 第二個不允許任何屬性"additionalProperties" : false除了那些在空集"properties" : {}中定義的屬性。換句話說,它不能擁有任何財產。

這個問題可以在標準草案5中解決。更多內容請見the following SO question

+0

所以問題是,這個「合併」只是一個提案,還沒有發佈呢?我檢查過http://json-schema.org/中的json模式規範,並沒有提及它。我們正在使用AJV進行驗證,但這並不支持合併。 – xbmono

+1

是的,你不能安全地應用它。如果可能,您可以將「additionalProperties」:false添加到引用的模式中。 – jruizaranguren

+0

你知道Json Schema Validator(https://github.com/daveclayton/json-schema-validator)是否支持$ merge?我剛剛意識到AJV增加了對$ merge的支持,但是我們正在使用Json模式驗證器,這是針對Java的,並且來自我在這裏可以看到的內容https://github.com/daveclayton/json-schema-validator/wiki/v5:-合併它支持$ merge但我不能得到它的工作?由於無法識別$ merge,它會返回錯誤 – xbmono

相關問題