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 9882ec7e276bee75ba8146055dd41eca960dbcf1..b70712eb75befcafd856d7c043f8e1fb4c226420 100644 |
| --- a/tools/json_schema_compiler/cpp_bundle_generator.py |
| +++ b/tools/json_schema_compiler/cpp_bundle_generator.py |
| @@ -8,6 +8,7 @@ from model import Platforms |
| from schema_util import CapitalizeFirstLetter |
| from schema_util import JsFunctionNameToClassName |
| +import collections |
| import copy |
| import json |
| import os |
| @@ -37,6 +38,34 @@ def _RemoveUnneededFields(schema): |
| _RemoveKey(ret, "noinline_doc", bool) |
| return ret |
| +def _PrefixSchemaWithNamespace(schema): |
|
lazyboy
2016/08/23 17:43:54
Add description, re: types and refs become fully q
Devlin
2016/08/23 22:02:43
Done.
|
| + assert isinstance(schema, dict), "Schema is unexpected type" |
| + namespace = schema['namespace'] |
| + def prefix(obj, key, force_presence): |
|
lazyboy
2016/08/23 17:43:55
nit: s/force_presence/mandatory
Devlin
2016/08/23 22:02:43
Done.
|
| + if not key in obj: |
| + assert not force_presence, ( |
| + 'Required key "%s" is not present in object.' % key) |
| + return |
| + if obj[key].find('.') == -1: |
|
lazyboy
2016/08/23 17:43:54
assert obj[key] is string?
Devlin
2016/08/23 22:02:43
Done.
|
| + obj[key] = '%s.%s' % (namespace, obj[key]) |
| + |
| + if 'types' in schema: |
| + for t in schema['types']: |
|
lazyboy
2016/08/23 17:43:54
assert that schema['types'] is a list.
Devlin
2016/08/23 22:02:43
Done.
|
| + assert isinstance(t, dict), "Type entry is unexpected type" |
| + prefix(t, 'id', True) |
| + prefix(t, 'customBindings', False) |
| + |
| + def prefix_refs(val): |
| + if type(val) is list: |
| + for sub_val in val: |
| + prefix_refs(sub_val) |
| + elif type(val) is dict or type(val) is collections.OrderedDict: |
| + prefix(val, '$ref', False) |
| + for key, sub_val in val.items(): |
| + prefix_refs(sub_val) |
| + prefix_refs(schema) |
| + return schema |
| + |
| class CppBundleGenerator(object): |
| """This class contains methods to generate code based on multiple schemas. |
| @@ -291,7 +320,8 @@ 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([_RemoveUnneededFields(api)], |
| + json_content = json.dumps([_PrefixSchemaWithNamespace( |
| + _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 |