Chromium Code Reviews| 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 70d52e71e580439a69b160a420dfbc4e5e0566eb..d7e965cbcc67c987d00567b03a4d4b1637ade8ed 100644 |
| --- a/chrome/common/extensions/docs/server2/api_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/api_data_source.py |
| @@ -5,6 +5,7 @@ |
| import copy |
| import logging |
| import os |
| +import collections |
| from file_system import FileNotFoundError |
| import third_party.json_schema_compiler.json_parse as json_parse |
| @@ -14,7 +15,7 @@ import third_party.json_schema_compiler.idl_parser as idl_parser |
| # Increment this if the data model changes for APIDataSource. |
| # This would include changes to model.py in json_schema_compiler! |
| -_VERSION = 17 |
| +_VERSION = 18 |
| def _RemoveNoDocs(item): |
| if json_parse.IsDict(item): |
| @@ -35,6 +36,46 @@ def _RemoveNoDocs(item): |
| item.remove(i) |
| return False |
| + |
| +def _InlineDocs(schema): |
| + """ Replace '$ref's that refer to inline_docs with the json for those docs |
|
cduvall
2013/04/18 00:02:41
no space after """
|
| + """ |
| + # Gather the types with inline_doc. |
| + types = schema.get('types') |
| + |
| + if types is None: |
| + return |
| + |
| + inline_docs = {} |
| + types_without_inline_doc = [] |
| + |
| + for type_ in types: |
| + if type_.get('inline_doc'): |
| + inline_docs[type_['id']] = type_ |
| + del type_['inline_doc'] |
| + del type_['id'] |
| + else: |
| + types_without_inline_doc.append(type_) |
| + |
| + schema['types'] = types_without_inline_doc |
| + |
| + def apply_inline(node): |
| + ref = node.get('$ref') |
| + |
| + if ref and ref in inline_docs: |
| + node.update(inline_docs[ref]) |
| + del node['$ref'] |
| + |
| + for k, v in node.iteritems(): |
| + if isinstance(v, collections.Mapping): |
| + apply_inline(v) |
| + elif isinstance(v, list): |
| + for i in v: |
| + if isinstance(i, collections.Mapping): |
| + apply_inline(i) |
| + |
| + apply_inline(schema) |
| + |
| def _CreateId(node, prefix): |
| if node.parent is not None and not isinstance(node.parent, model.Namespace): |
| return '-'.join([prefix, node.parent.simple_name, node.simple_name]) |
| @@ -57,6 +98,7 @@ class _JSCModel(object): |
| if _RemoveNoDocs(clean_json): |
| self._namespace = None |
| else: |
| + _InlineDocs(clean_json) |
| self._namespace = model.Namespace(clean_json, clean_json['namespace']) |
| def _FormatDescription(self, description): |