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

Unified Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 11827026: Overhaul JSON Schema Compiler to support a number of features required to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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: chrome/common/extensions/docs/server2/api_data_source.py
diff --git a/chrome/common/extensions/docs/server2/api_data_source.py b/chrome/common/extensions/docs/server2/api_data_source.py
index 151226549c44fd9c055b8c8816e45f089ee170e2..eac56164da68669af7038392256b856af179d022 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -17,7 +17,7 @@ import third_party.json_schema_compiler.idl_parser as idl_parser
# the caches used by APIDataSource. This would include changes to model.py in
# JSON schema compiler! This allows the cache to be invalidated without having
# to flush memcache on the production server.
-_VERSION = 12
+_VERSION = 13
def _RemoveNoDocs(item):
if json_parse.IsDict(item):
@@ -79,13 +79,15 @@ class _JSCModel(object):
return {}
return {
'name': self._namespace.name,
- 'types': [self._GenerateType(t) for t in self._namespace.types.values()
- if t.type_ != model.PropertyType.ADDITIONAL_PROPERTIES],
+ 'types': self._GenerateTypes(self._namespace.types.values()),
'functions': self._GenerateFunctions(self._namespace.functions),
'events': self._GenerateEvents(self._namespace.events),
'properties': self._GenerateProperties(self._namespace.properties)
}
+ def _GenerateTypes(self, types):
+ return [self._GenerateType(t) for t in types]
+
def _GenerateType(self, type_):
type_dict = {
'name': type_.simple_name,
@@ -168,41 +170,49 @@ class _JSCModel(object):
return callback_dict
def _GenerateProperties(self, properties):
- return [self._GenerateProperty(v) for v in properties.values()
- if v.type_ != model.PropertyType.ADDITIONAL_PROPERTIES]
+ return [self._GenerateProperty(v) for v in properties.values()]
def _GenerateProperty(self, property_):
+ type_ = property_.type_
+
# Make sure we generate property info for arrays, too.
# TODO(kalman): what about choices?
- if property_.type_ == model.PropertyType.ARRAY:
- properties = property_.item_type.properties
+ if type_.property_type == model.PropertyType.ARRAY:
+ properties = type_.item_type.properties
else:
- properties = property_.properties
+ properties = type_.properties
property_dict = {
'name': property_.simple_name,
'optional': property_.optional,
'description': self._FormatDescription(property_.description),
- 'properties': self._GenerateProperties(properties),
- 'functions': self._GenerateFunctions(property_.functions),
+ 'properties': self._GenerateProperties(type_.properties),
+ 'functions': self._GenerateFunctions(type_.functions),
'parameters': [],
'returns': None,
'id': _CreateId(property_, 'property')
}
- for param in property_.params:
- property_dict['parameters'].append(self._GenerateProperty(param))
- if property_.returns:
- property_dict['returns'] = self._GenerateProperty(property_.returns)
+
+ if type_.property_type == model.PropertyType.FUNCTION:
+ function = type_.function
+ for param in function.params:
+ property_dict['parameters'].append(self._GenerateProperty(param))
+ if function.returns:
+ property_dict['returns'] = self._GenerateProperty(function.returns)
+
if (property_.parent is not None and
not isinstance(property_.parent, model.Namespace)):
property_dict['parent_name'] = property_.parent.simple_name
- if property_.has_value:
- if isinstance(property_.value, int):
- property_dict['value'] = _FormatValue(property_.value)
+
+ value = property_.value
+ if value is not None:
+ if isinstance(value, int):
+ property_dict['value'] = _FormatValue(value)
else:
- property_dict['value'] = property_.value
+ property_dict['value'] = value
else:
- self._RenderTypeInformation(property_, property_dict)
+ self._RenderTypeInformation(type_, property_dict)
+
return property_dict
def _GenerateCallbackProperty(self, callback):
@@ -218,28 +228,27 @@ class _JSCModel(object):
property_dict['parent_name'] = callback.parent.simple_name
return property_dict
- def _RenderTypeInformation(self, property_, dst_dict):
- if property_.type_ == model.PropertyType.CHOICES:
- dst_dict['choices'] = [self._GenerateProperty(c)
- for c in property_.choices.values()]
+ def _RenderTypeInformation(self, type_, dst_dict):
+ if type_.property_type == model.PropertyType.CHOICES:
+ dst_dict['choices'] = self._GenerateTypes(type_.choices)
# We keep track of which is last for knowing when to add "or" between
# choices in templates.
if len(dst_dict['choices']) > 0:
dst_dict['choices'][-1]['last'] = True
- elif property_.type_ == model.PropertyType.REF:
- dst_dict['link'] = self._GetLink(property_.ref_type)
- elif property_.type_ == model.PropertyType.ARRAY:
- dst_dict['array'] = self._GenerateProperty(property_.item_type)
- elif property_.type_ == model.PropertyType.ENUM:
+ elif type_.property_type == model.PropertyType.REF:
+ dst_dict['link'] = self._GetLink(type_.ref_type)
+ elif type_.property_type == model.PropertyType.ARRAY:
+ dst_dict['array'] = self._GenerateType(type_.item_type)
+ elif type_.property_type == model.PropertyType.ENUM:
dst_dict['enum_values'] = []
- for enum_value in property_.enum_values:
+ for enum_value in type_.enum_values:
dst_dict['enum_values'].append({'name': enum_value})
if len(dst_dict['enum_values']) > 0:
dst_dict['enum_values'][-1]['last'] = True
- elif property_.instance_of is not None:
- dst_dict['simple_type'] = property_.instance_of.lower()
+ elif type_.instance_of is not None:
+ dst_dict['simple_type'] = type_.instance_of.lower()
else:
- dst_dict['simple_type'] = property_.type_.name.lower()
+ dst_dict['simple_type'] = type_.property_type.name.lower()
class _LazySamplesGetter(object):
"""This class is needed so that an extensions API page does not have to fetch

Powered by Google App Engine
This is Rietveld 408576698