I'll never be happy with a textual specification of this JSON file.
I always prefer a formal description with a schema which allows to use
a verification tool.
So, I try to use Rx, see
http://rx.codesimply.com/
And I write my first Rx schema, see below :
(Obviously, this schema needs many refinements)
{
"type": "//rec",
"optional": {
"name": "//str",
"author": "//str",
"api_base_url": "//str",
"api_format": "//str",
"version": "//str",
"authentication": "//bool",
},
"required": {
"methods": {
"type": "//map",
"values": {
"type": "//rec",
"required": {
"method": "//str",
"path": "//str",
},
"optional": {
"params": {
"type": "//arr",
"contents": {
"type": "//str"
},
},
"required": {
"type" : "//arr",
"contents": {
"type": "//str"
},
},
"expected": {
"type" : "//arr",
"contents": {
"type": "//int"
},
},
"description": "//str",
"authentication": "//bool",
"api_base_url": "//str",
"format": "//str",
},
},
},
},
}
The online validator (
http://rx.codesimply.com/demo.html) allows to
check the following example :
{
"name": "CouchDB",
"author": "franck cuny <
fra...@lumberjaph.net>",
"api_base_url": "
http://api.twitter.com/1/",
"api_format": "json",
"version": "0.1",
"authentication": true,
"methods": {
"public_timeline": {
"params" : [
"trim_user",
"include_entities"
],
"required" : [
"format"
],
"path": "/statuses/public_timeline.:format",
"method": "GET"
}
}
}
A small CLI checker could be easily written in Perl5 with Data::Rx.
Another remark, when I added an implementation of a strict mode for
parameter,
I am not happy with the field named "params". I prefer the
complementary pair "required"/"optional".
François