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

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: Update comment, return copy 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..9882ec7e276bee75ba8146055dd41eca960dbcf1 100644
--- a/tools/json_schema_compiler/cpp_bundle_generator.py
+++ b/tools/json_schema_compiler/cpp_bundle_generator.py
@@ -8,26 +8,34 @@ from model import Platforms
from schema_util import CapitalizeFirstLetter
from schema_util import JsFunctionNameToClassName
+import copy
import json
import os
import re
-def _RemoveDescriptions(node):
- """Returns a copy of |schema| with "description" fields removed.
- """
+def _RemoveKey(node, key, type_restriction):
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]
- return node
+ 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(schema):
+ """Returns a copy of |schema| with fields that aren't necessary at runtime
+ removed.
+ """
+ # Return a copy so that we don't pollute the global api object, which may be
+ # used elsewhere.
+ ret = copy.deepcopy(schema)
Devlin 2016/08/22 17:08:58 Note: I changed this (back) to returning a copy, b
+ _RemoveKey(ret, "description", basestring)
+ _RemoveKey(ret, "compiler_options", dict)
+ _RemoveKey(ret, "nodoc", bool)
+ _RemoveKey(ret, "noinline_doc", bool)
+ return ret
class CppBundleGenerator(object):
@@ -283,7 +291,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