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

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

Issue 14322003: Inline docs render properly in extensions doc server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small test changes Created 7 years, 8 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 81948337bf979da6bd8bfd1006523e1be3f0991a..9695fd6dcebed8a20b8653c536f31dafa4272e1b 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
import third_party.json_schema_compiler.json_parse as json_parse
import third_party.json_schema_compiler.model as model
@@ -27,6 +28,43 @@ 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_
+ if type_.get('description'):
+ del type_['description']
+ del type_['inline_doc']
+ del type_['id']
+ else:
+ types_without_inline_doc.append(type_)
+ schema['types'] = types_without_inline_doc
+
+ def apply_inline(node):
+ if isinstance(node, list):
+ for i in node:
+ apply_inline(i)
+ elif isinstance(node, collections.Mapping):
+ 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():
+ apply_inline(v)
+
+ 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 +87,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):
« no previous file with comments | « chrome/common/extensions/api/downloads.idl ('k') | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698