2017-02-21 19 views
3

可以向json模式屬性添加額外的或自定義的元數據(標題和描述除外)?json-schema額外的元數據

理想我想添加一些元數據,像這樣:

//... 
"properties": { 
    "contactFullName": { 
    "$ref": "#/definitions/fullName", 
    "custom": "my custom metadata here" 
    } 
} 
//... 

你能添加一些definitions允許嗎?

回答

6

您不必爲使用其他元數據關鍵字而特別做任何事情。你可以使用它們。在JSON模式中,包含未定義的關鍵字並不是一個錯誤。任何不具有JSON模式語義的應該被安靜地忽略。所以,下面的模式是完全有效的,不應與任何驗證器實現衝突。

{ 
    "title": "Foo", 
    "description": "All the foo you can GET", 
    "version": "1.0.3", 
    "author": "Jason Desrosiers", 
    "type": "object", 
    "properties": { 
    "id": { "type": "string" } 
    } 
} 
2

你可以使用description屬性,並在那裏放置一個特定的結構,然後根據需要進行解釋和應用(就像JSON模式內的JSON,可以這麼說)。