When Aaron talked about the Chrome extension API he mentioned how he would see if JSON Schema could help them have a JSON heavy API and allow them to easily validate.
Read The Full Tutorial.
When Aaron talked about the Chrome extension API he mentioned how he would see if JSON Schema could help them have a JSON heavy API and allow them to easily validate.
He has quickly reported back and is happy with the results.
Something like this:
PLAIN TEXT JAVASCRIPT:
1. 2. chromium.tabs.createTab = function(tab, callback) { 3. validate(arguments, arguments.callee.params); 4. sendRequest(CreateTab, tab, callback); 5. }; 6. 7. chromium.tabs.createTab.params = [ 8. { 9. type: "object", 10. properties: { 11. windowId: chromium.types.optPInt, 12. url: chromium.types.optStr, 13. selected: chromium.types.optBool 14. }, 15. additionalProperties: false 16. }, 17. chromium.types.optFun 18. ]; 19.
will give you errors such as:
Invalid value for parameter 0. Property windowId: expected integer, got string.
It will be interesting to see how the APIs look when you go for this style throughout. Looking forward to see more.
source: ajaxian
|