OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import copy | 5 import copy |
6 import os.path | 6 import os.path |
7 import re | 7 import re |
8 | 8 |
9 class Model(object): | 9 class Model(object): |
10 """Model of all namespaces that comprise an API. | 10 """Model of all namespaces that comprise an API. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 Properties: | 63 Properties: |
64 - |name| the type name | 64 - |name| the type name |
65 - |description| the description of the type (if provided) | 65 - |description| the description of the type (if provided) |
66 - |properties| a map of property unix_names to their model.Property | 66 - |properties| a map of property unix_names to their model.Property |
67 - |functions| a map of function names to their model.Function | 67 - |functions| a map of function names to their model.Function |
68 - |from_client| indicates that instances of the Type can originate from the | 68 - |from_client| indicates that instances of the Type can originate from the |
69 users of generated code, such as top-level types and function results | 69 users of generated code, such as top-level types and function results |
70 - |from_json| indicates that instances of the Type can originate from the | 70 - |from_json| indicates that instances of the Type can originate from the |
71 JSON (as described by the schema), such as top-level types and function | 71 JSON (as described by the schema), such as top-level types and function |
72 parameters | 72 parameters |
| 73 - |type_| the PropertyType of this Type |
| 74 - |item_type| if this is an array, the type of items in the array |
73 """ | 75 """ |
74 def __init__(self, parent, name, json): | 76 def __init__(self, parent, name, json): |
75 if not ( | 77 if json.get('type') == 'array': |
76 'properties' in json or | 78 self.type_ = PropertyType.ARRAY |
77 'additionalProperties' in json or | 79 self.item_type = Property(self, name + "Element", json['items'], |
78 'functions' in json): | 80 from_json=True, |
79 raise ParseException(name + " has no properties or functions") | 81 from_client=True) |
| 82 else: |
| 83 if not ( |
| 84 'properties' in json or |
| 85 'additionalProperties' in json or |
| 86 'functions' in json): |
| 87 raise ParseException(name + " has no properties or functions") |
| 88 self.type_ = PropertyType.OBJECT |
80 self.name = name | 89 self.name = name |
81 self.description = json.get('description') | 90 self.description = json.get('description') |
82 self.from_json = True | 91 self.from_json = True |
83 self.from_client = True | 92 self.from_client = True |
84 self.properties = {} | 93 self.properties = {} |
85 self.functions = {} | 94 self.functions = {} |
86 self.parent = parent | 95 self.parent = parent |
87 for function_json in json.get('functions', []): | 96 for function_json in json.get('functions', []): |
88 if not function_json.get('nocompile', False): | 97 if not function_json.get('nocompile', False): |
89 self.functions[function_json['name']] = Function(self, function_json) | 98 self.functions[function_json['name']] = Function(self, function_json) |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 """Returns the hierarchy of the given model entity.""" | 334 """Returns the hierarchy of the given model entity.""" |
326 hierarchy = [] | 335 hierarchy = [] |
327 while entity: | 336 while entity: |
328 try: | 337 try: |
329 hierarchy.append(entity.name) | 338 hierarchy.append(entity.name) |
330 except AttributeError: | 339 except AttributeError: |
331 hierarchy.append(repr(entity)) | 340 hierarchy.append(repr(entity)) |
332 entity = entity.parent | 341 entity = entity.parent |
333 hierarchy.reverse() | 342 hierarchy.reverse() |
334 return hierarchy | 343 return hierarchy |
OLD | NEW |