Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: tools/json_schema_compiler/model.py

Issue 9456007: Add wider support to json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rework, add nocompile to extension.json Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/model.py
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 5ff394af46c471d16ad770a8261580091b1e2ac9..934978b7e47d473487490d6cfbfc9e4cb84390f0 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -60,13 +60,19 @@ class Type(object):
- |name| the type name
- |description| the description of the type (if provided)
- |properties| a map of property names to their model.Property
+ - |from_api| indicates that the type is coming from the API caller
+ - |to_api| indicates that the type is going to the API caller
not at google - send to devlin 2012/02/26 23:51:53 This makes a lot more sense. I think it could stil
not at google - send to devlin 2012/02/26 23:53:34 Heh, fail, changed my mind right after writing tha
calamity 2012/02/27 04:57:30 Done. Changed to from_user/from_json
"""
def __init__(self, json):
self.name = json['id']
self.description = json.get('description')
+ self.from_api = True
+ self.to_api = True
self.properties = {}
for prop_name, prop_json in json['properties'].items():
- self.properties[prop_name] = Property(prop_name, prop_json)
+ self.properties[prop_name] = Property(prop_name, prop_json,
+ from_api=True,
+ to_api=True)
class Callback(object):
"""A callback parameter to a Function.
@@ -81,7 +87,8 @@ class Callback(object):
return
elif len(params) == 1:
param = params[0]
- self.params.append(Property(param['name'], param))
+ self.params.append(Property(param['name'], param,
+ to_api=True))
else:
raise AssertionError("Callbacks can have at most a single parameter")
@@ -106,12 +113,16 @@ class Function(object):
assert (not self.callback), self.name + " has more than one callback"
self.callback = Callback(param)
else:
- self.params.append(Property(param['name'], param))
- assert (self.callback), self.name + " does not support callback"
+ self.params.append(Property(param['name'], param,
+ from_api=True))
class Property(object):
"""A property of a type OR a parameter to a function.
+ Parameters:
+ from_api: indicates whether the property is coming from the API caller
+ to_api: indicates whether the property will to go to the API caller
+
Properties:
- |name| name of the property as in the json. This shouldn't change since
it is the key used to access DictionaryValues
@@ -125,9 +136,9 @@ class Property(object):
ARRAY
- |properties| the properties of an OBJECT parameter
"""
- def __init__(self, name, json):
- if not re.match('^[a-z][a-zA-Z0-9]*$', name):
- raise AssertionError('Name %s must be lowerCamelCase' % name)
+ def __init__(self, name, json,
+ from_api=False,
Yoyo Zhou 2012/02/24 23:39:47 Unless I'm reading something incorrectly, it looks
calamity 2012/02/27 04:57:30 The Property is used as a Type if it is an OBJECT.
+ to_api=False):
self.name = name
self._unix_name = _UnixName(self.name)
self._unix_name_used = False
@@ -154,13 +165,19 @@ class Property(object):
elif json_type == 'number':
self.type_ = PropertyType.DOUBLE
elif json_type == 'array':
- self.item_type = Property(name + "Element", json['items'])
+ self.item_type = Property(name + "Element", json['items'],
+ from_api,
+ to_api)
self.type_ = PropertyType.ARRAY
elif json_type == 'object':
self.properties = {}
self.type_ = PropertyType.OBJECT
+ self.from_api = from_api
+ self.to_api = to_api
for key, val in json['properties'].items():
- self.properties[key] = Property(key, val)
+ self.properties[key] = Property(key, val,
+ from_api,
+ to_api)
else:
raise NotImplementedError(json_type)
elif 'choices' in json:
@@ -168,7 +185,9 @@ class Property(object):
self.choices = {}
self.type_ = PropertyType.CHOICES
for choice_json in json['choices']:
- choice = Property(self.name, choice_json)
+ choice = Property(self.name, choice_json,
+ from_api,
+ to_api)
# A choice gets its unix_name set in
# cpp_type_generator.GetExpandedChoicesInParams
choice._unix_name = None

Powered by Google App Engine
This is Rietveld 408576698