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

Unified Diff: tools/json_schema_compiler/cpp_bundle_generator.py

Issue 2266573003: [Extensions] Trim some fat around what we use in generated schemas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/cpp_bundle_generator.py
diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py
index 168da10511c515b01250e9d67c701d6139488730..c2cfa6ba920bc1c0f11433823a2cdce047f7deb9 100644
--- a/tools/json_schema_compiler/cpp_bundle_generator.py
+++ b/tools/json_schema_compiler/cpp_bundle_generator.py
@@ -13,20 +13,23 @@ import os
import re
-def _RemoveDescriptions(node):
+def _RemoveKey(node, key, type_restriction):
+ if isinstance(node, dict):
+ if key in node and isinstance(node[key], type_restriction):
+ del node[key]
+ for value in node.values():
+ _RemoveKey(value, key, type_restriction)
+ elif isinstance(node, list):
+ for value in node:
+ _RemoveKey(value, key, type_restriction)
+
+def _RemoveUnneededFields(node):
"""Returns a copy of |schema| with "description" fields removed.
Devlin 2016/08/20 00:53:50 Whoops - will update this comment.
lazyboy 2016/08/20 01:34:31 Acknowledged.
"""
- if isinstance(node, dict):
- result = {}
- for key, value in node.items():
- # Some schemas actually have properties called "description", so only
- # remove descriptions that have string values.
- if key == 'description' and isinstance(value, basestring):
- continue
- result[key] = _RemoveDescriptions(value)
- return result
- if isinstance(node, list):
- return [_RemoveDescriptions(v) for v in node]
+ _RemoveKey(node, "description", basestring)
+ _RemoveKey(node, "compiler_options", dict)
+ _RemoveKey(node, "nodoc", bool)
+ _RemoveKey(node, "noinline_doc", bool)
return node
@@ -283,7 +286,7 @@ class _SchemasCCGenerator(object):
for api in self._bundle._api_defs:
namespace = self._bundle._model.namespaces[api.get('namespace')]
# JSON parsing code expects lists of schemas, so dump a singleton list.
- json_content = json.dumps([_RemoveDescriptions(api)],
+ json_content = json.dumps([_RemoveUnneededFields(api)],
separators=(',', ':'))
# Escape all double-quotes and backslashes. For this to output a valid
# JSON C string, we need to escape \ and ". Note that some schemas are
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698