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 81948337bf979da6bd8bfd1006523e1be3f0991a..d8d1302cdf63b437c655b1d72a649d62331fa694 100644 |
| --- a/chrome/common/extensions/docs/server2/api_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/api_data_source.py |
| @@ -5,12 +5,17 @@ |
| import copy |
| import logging |
| import os |
| +import collections |
| import third_party.json_schema_compiler.json_parse as json_parse |
| import third_party.json_schema_compiler.model as model |
| import third_party.json_schema_compiler.idl_schema as idl_schema |
| 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 = 18 |
| + |
|
not at google - send to devlin
2013/04/25 00:19:35
if you sync (maybe you already have) the version s
|
| def _RemoveNoDocs(item): |
| if json_parse.IsDict(item): |
| if item.get('nodoc', False): |
| @@ -27,6 +32,42 @@ 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. |
| + """ |
| + types = schema.get('types') |
| + if types is None: |
| + return |
| + |
| + inline_docs = {} |
| + types_without_inline_doc = [] |
| + |
| + # Gather the types with inline_doc. |
| + for type_ in types: |
| + if type_.get('inline_doc'): |
| + inline_docs[type_['id']] = type_ |
| + del type_['inline_doc'] |
| + del type_['id'] |
|
not at google - send to devlin
2013/04/25 00:19:35
you'll need to delete the description too?
jshumway
2013/04/25 01:48:37
Got it
|
| + 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]) |
| + |
| + 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): |
|
not at google - send to devlin
2013/04/25 00:19:35
maybe this function should be rotated a bit so tha
jshumway
2013/04/25 01:48:37
I did rotate it but two checks are still needed: o
|
| + 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]) |
| @@ -49,6 +90,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): |