Activate your free membership today | Log-in

Monday, April 20th, 2009

How JSON Schema is turning out for the Chrome extension APIs

Category: Chrome, JSON

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:

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.

Posted by Dion Almaer at 5:19 am
4 Comments

++++-
4.2 rating from 10 votes

4 Comments »

Comments feed TrackBack URI

Aliasing common types with JS variables like Aaron has done is excellent way of making more succinct, readable schemas by utilizing the local language features.

Comment by kriszyp — April 20, 2009

The code example has been cut short…

Comment by icoloma — April 20, 2009

Nah, my fault. It’s fine.

My Firefox is going maracas these days…

Comment by icoloma — April 20, 2009

Pass4sure is an expert in providing the most valuable training materials for IT certification exams. Comprehensive and latest practice exams, 100% pass guarantee policy, professional pre-sale and post-sale service, all these protect your way on preparation for IT certification exams. Numerous vendors provide customers with a wide rang of choices.The Most Popular exams List :640-721642-642 646-656 1Y0-A11 650-180 642-566 350-029 642-105 642-681 642-072 350-029 XK0-002642-072 640-802 642-681 HP0-J22 1Y0-A11 310-065 220-701 EX0-101 642-873 312-50 640-802 Click Pass 4 Sure to get more information!

Comment by pass4sure — February 24, 2010

Leave a comment

You must be logged in to post a comment.