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

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

Issue 10828407: JSON Schema Compiler supports Enums as types. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: more testing of optional enums Created 8 years, 3 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 - |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
75 """ 75 """
76 def __init__(self, parent, name, json): 76 def __init__(self, parent, name, json):
77 if json.get('type') == 'array': 77 if json.get('type') == 'array':
78 self.type_ = PropertyType.ARRAY 78 self.type_ = PropertyType.ARRAY
79 self.item_type = Property(self, name + "Element", json['items'], 79 self.item_type = Property(self, name + "Element", json['items'],
80 from_json=True, 80 from_json=True,
81 from_client=True) 81 from_client=True)
82 elif json.get('type') == 'string': 82 elif json.get('type') == 'string':
83 self.type_ = PropertyType.STRING 83 self.type_ = PropertyType.STRING
84 elif 'enum' in json:
85 self.enum_values = []
86 for value in json['enum']:
87 self.enum_values.append(value)
88 self.type_ = PropertyType.ENUM
84 else: 89 else:
85 if not ( 90 if not (
86 'properties' in json or 91 'properties' in json or
87 'additionalProperties' in json or 92 'additionalProperties' in json or
88 'functions' in json or 93 'functions' in json or
89 'events' in json): 94 'events' in json):
90 raise ParseException(self, name + " has no properties or functions") 95 raise ParseException(self, name + " has no properties or functions")
91 self.type_ = PropertyType.OBJECT 96 self.type_ = PropertyType.OBJECT
92 self.name = name 97 self.name = name
93 self.description = json.get('description') 98 self.description = json.get('description')
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 of |json|. 391 of |json|.
387 """ 392 """
388 model.properties = {} 393 model.properties = {}
389 for name, property_json in json.get('properties', {}).items(): 394 for name, property_json in json.get('properties', {}).items():
390 model.properties[name] = Property( 395 model.properties[name] = Property(
391 model, 396 model,
392 name, 397 name,
393 property_json, 398 property_json,
394 from_json=from_json, 399 from_json=from_json,
395 from_client=from_client) 400 from_client=from_client)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698