Chromium Code Reviews| 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 |