Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: tools/json_schema_compiler/model.py

Issue 10800047: Extension Docs Server Version 2: Various fixes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ParseException(Exception): 9 class ParseException(Exception):
10 """Thrown when data in the model is invalid. 10 """Thrown when data in the model is invalid.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 _AddProperties(self, json) 57 _AddProperties(self, json)
58 58
59 class Type(object): 59 class Type(object):
60 """A Type defined in the json. 60 """A Type defined in the json.
61 61
62 Properties: 62 Properties:
63 - |name| the type name 63 - |name| the type name
64 - |description| the description of the type (if provided) 64 - |description| the description of the type (if provided)
65 - |properties| a map of property unix_names to their model.Property 65 - |properties| a map of property unix_names to their model.Property
66 - |functions| a map of function names to their model.Function 66 - |functions| a map of function names to their model.Function
67 - |events| a map of event names to their model.Event
67 - |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
68 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
69 - |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
70 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
71 parameters 72 parameters
72 - |type_| the PropertyType of this Type 73 - |type_| the PropertyType of this Type
73 - |item_type| if this is an array, the type of items in the array 74 - |item_type| if this is an array, the type of items in the array
74 """ 75 """
75 def __init__(self, parent, name, json): 76 def __init__(self, parent, name, json):
76 if json.get('type') == 'array': 77 if json.get('type') == 'array':
77 self.type_ = PropertyType.ARRAY 78 self.type_ = PropertyType.ARRAY
78 self.item_type = Property(self, name + "Element", json['items'], 79 self.item_type = Property(self, name + "Element", json['items'],
79 from_json=True, 80 from_json=True,
80 from_client=True) 81 from_client=True)
81 elif json.get('type') == 'string': 82 elif json.get('type') == 'string':
82 self.type_ = PropertyType.STRING 83 self.type_ = PropertyType.STRING
83 else: 84 else:
84 if not ( 85 if not (
85 'properties' in json or 86 'properties' in json or
86 'additionalProperties' in json or 87 'additionalProperties' in json or
87 'functions' in json): 88 'functions' in json):
88 raise ParseException(self, name + " has no properties or functions") 89 raise ParseException(self, name + " has no properties or functions")
89 self.type_ = PropertyType.OBJECT 90 self.type_ = PropertyType.OBJECT
90 self.name = name 91 self.name = name
91 self.description = json.get('description') 92 self.description = json.get('description')
92 self.from_json = True 93 self.from_json = True
93 self.from_client = True 94 self.from_client = True
94 self.parent = parent 95 self.parent = parent
95 _AddFunctions(self, json) 96 _AddFunctions(self, json)
97 _AddEvents(self, json)
96 _AddProperties(self, json, from_json=True, from_client=True) 98 _AddProperties(self, json, from_json=True, from_client=True)
97 99
98 additional_properties_key = 'additionalProperties' 100 additional_properties_key = 'additionalProperties'
99 additional_properties = json.get(additional_properties_key) 101 additional_properties = json.get(additional_properties_key)
100 if additional_properties: 102 if additional_properties:
101 self.properties[additional_properties_key] = Property( 103 self.properties[additional_properties_key] = Property(
102 self, 104 self,
103 additional_properties_key, 105 additional_properties_key,
104 additional_properties, 106 additional_properties,
105 is_additional_properties=True) 107 is_additional_properties=True)
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 # handled in pure Javascript on the render process (and .: never reach 354 # handled in pure Javascript on the render process (and .: never reach
353 # C++ let alone the browser). 355 # C++ let alone the browser).
354 if property_json.get('type') == 'function': 356 if property_json.get('type') == 'function':
355 continue 357 continue
356 model.properties[name] = Property( 358 model.properties[name] = Property(
357 model, 359 model,
358 name, 360 name,
359 property_json, 361 property_json,
360 from_json=from_json, 362 from_json=from_json,
361 from_client=from_client) 363 from_client=from_client)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698