Index: tools/json_schema_compiler/compiler.py |
diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py |
index 6d3dd632aa4f1b72f2379e6807a5a539f82f3717..7965d18d40f003000fee5d454c6aef514c002409 100644 |
--- a/tools/json_schema_compiler/compiler.py |
+++ b/tools/json_schema_compiler/compiler.py |
@@ -28,7 +28,7 @@ import sys |
if __name__ == '__main__': |
parser = optparse.OptionParser( |
description='Generates a C++ model of an API from JSON schema', |
- usage='usage: %prog [option]... schema [referenced_schema]...') |
+ usage='usage: %prog [option]... schema') |
parser.add_option('-r', '--root', default='.', |
help='logical include root directory. Path to schema files from specified' |
'dir will be the include path.') |
@@ -44,24 +44,27 @@ if __name__ == '__main__': |
root_namespace = opts.namespace |
schema = os.path.normpath(args[0]) |
- referenced_schemas = args[1:] |
api_model = model.Model() |
- # Load type dependencies into the model. |
- for referenced_schema_path in referenced_schemas: |
- with open(referenced_schema_path, 'r') as referenced_schema_file: |
- referenced_api_defs = json.loads(referenced_schema_file.read()) |
- |
- for namespace in referenced_api_defs: |
- api_model.AddNamespace(namespace, |
- os.path.relpath(referenced_schema_path, opts.root)) |
# Actually generate for source file. |
with open(schema, 'r') as schema_file: |
api_defs = json.loads(schema_file.read()) |
for target_namespace in api_defs: |
+ referenced_schemas = target_namespace.get('dependencies', []) |
+ # Load type dependencies into the model. |
+ for referenced_schema in referenced_schemas: |
+ referenced_schema_path = os.path.join( |
+ os.path.dirname(schema), referenced_schema + '.json') |
+ with open(referenced_schema_path, 'r') as referenced_schema_file: |
+ referenced_api_defs = json.loads(referenced_schema_file.read()) |
+ |
+ for namespace in referenced_api_defs: |
+ api_model.AddNamespace(namespace, |
+ os.path.relpath(referenced_schema_path, opts.root)) |
+ |
# Gets the relative path from opts.root to the schema to correctly determine |
# the include path. |
relpath = os.path.relpath(schema, opts.root) |