| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from collections import defaultdict, Mapping | 5 from collections import defaultdict, Mapping |
| 6 import traceback | 6 import traceback |
| 7 | 7 |
| 8 from third_party.json_schema_compiler import json_parse, idl_schema, idl_parser | 8 from third_party.json_schema_compiler import json_parse, idl_schema, idl_parser |
| 9 | 9 |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 ref = node.get('$ref') | 82 ref = node.get('$ref') |
| 83 if ref and ref in inline_docs: | 83 if ref and ref in inline_docs: |
| 84 node.update(inline_docs[ref]) | 84 node.update(inline_docs[ref]) |
| 85 del node['$ref'] | 85 del node['$ref'] |
| 86 for k, v in node.iteritems(): | 86 for k, v in node.iteritems(): |
| 87 apply_inline(v) | 87 apply_inline(v) |
| 88 | 88 |
| 89 apply_inline(schema) | 89 apply_inline(schema) |
| 90 | 90 |
| 91 | 91 |
| 92 def ProcessSchema(path, file_data): | 92 def ProcessSchema(path, file_data, inline=False): |
| 93 '''Parses |file_data| using a method determined by checking the | 93 '''Parses |file_data| using a method determined by checking the extension of |
| 94 extension of the file at the given |path|. Then, trims 'nodoc' and handles | 94 the file at the given |path|. Then, trims 'nodoc' and if |inline| is given |
| 95 inlineable types from the parsed schema data. | 95 and True, handles inlineable types from the parsed schema data. |
| 96 ''' | 96 ''' |
| 97 def trim_and_inline(schema, is_idl=False): | 97 def trim_and_inline(schema, is_idl=False): |
| 98 '''Modifies an API schema in place by removing nodes that shouldn't be | 98 '''Modifies an API schema in place by removing nodes that shouldn't be |
| 99 documented and inlining schema types that are only referenced once. | 99 documented and inlining schema types that are only referenced once. |
| 100 ''' | 100 ''' |
| 101 if RemoveNoDocs(schema): | 101 if RemoveNoDocs(schema): |
| 102 # A return of True signifies that the entire schema should not be | 102 # A return of True signifies that the entire schema should not be |
| 103 # documented. Otherwise, only nodes that request 'nodoc' are removed. | 103 # documented. Otherwise, only nodes that request 'nodoc' are removed. |
| 104 return None | 104 return None |
| 105 if is_idl: | 105 if inline: |
| 106 DetectInlineableTypes(schema) | 106 if is_idl: |
| 107 InlineDocs(schema) | 107 DetectInlineableTypes(schema) |
| 108 InlineDocs(schema) |
| 108 return schema | 109 return schema |
| 109 | 110 |
| 110 if path.endswith('.idl'): | 111 if path.endswith('.idl'): |
| 111 idl = idl_schema.IDLSchema(idl_parser.IDLParser().ParseData(file_data)) | 112 idl = idl_schema.IDLSchema(idl_parser.IDLParser().ParseData(file_data)) |
| 112 # Wrap the result in a list so that it behaves like JSON API data. | 113 # Wrap the result in a list so that it behaves like JSON API data. |
| 113 return [trim_and_inline(idl.process()[0], is_idl=True)] | 114 return [trim_and_inline(idl.process()[0], is_idl=True)] |
| 114 | 115 |
| 115 try: | 116 try: |
| 116 schemas = json_parse.Parse(file_data) | 117 schemas = json_parse.Parse(file_data) |
| 117 except: | 118 except: |
| 118 raise ValueError('Cannot parse "%s" as JSON:\n%s' % | 119 raise ValueError('Cannot parse "%s" as JSON:\n%s' % |
| 119 (path, traceback.format_exc())) | 120 (path, traceback.format_exc())) |
| 120 for schema in schemas: | 121 for schema in schemas: |
| 121 # Schemas could consist of one API schema (data for a specific API file) | 122 # Schemas could consist of one API schema (data for a specific API file) |
| 122 # or multiple (data from extension_api.json). | 123 # or multiple (data from extension_api.json). |
| 123 trim_and_inline(schema) | 124 trim_and_inline(schema) |
| 124 return schemas | 125 return schemas |
| OLD | NEW |