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

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: 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 dcb1736a1b690c93cbde3599caec35538e794daa..bb6f22d73ec39ede465425cddfb2d687593eb806 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -16,7 +16,7 @@ import third_party.json_schema_compiler.idl_parser as idl_parser
# Increment this version when there are changes to the data stored in any of
# the caches used by APIDataSource. This allows the cache to be invalidated
# without having to flush memcache on the production server.
-_VERSION = 8
+_VERSION = 9
def _RemoveNoDocs(item):
if json_parse.IsDict(item):
@@ -77,13 +77,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,
@@ -163,60 +165,62 @@ 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_
property_dict = {
'name': property_.simple_name,
'optional': property_.optional,
'description': self._FormatDescription(property_.description),
- 'properties': self._GenerateProperties(property_.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
else:
property_dict['parent_name'] = None
- 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 _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
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