| Index: tools/json_schema_compiler/model.py
|
| diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
|
| index 2351ecd1f999b17bf7077c52d8baaeb00e09cd83..c40abc3387568e4c50545b2a96eaf1e98fffd866 100644
|
| --- a/tools/json_schema_compiler/model.py
|
| +++ b/tools/json_schema_compiler/model.py
|
| @@ -150,6 +150,8 @@ class Property(object):
|
| - |optional| a boolean representing whether the property is optional
|
| - |description| a description of the property (if provided)
|
| - |type_| the model.PropertyType of this property
|
| + - |compiled_type| the model.PropertyType that this property should be
|
| + compiled to from the JSON. Defaults to type_.
|
| - |ref_type| the type that the REF property is referencing. Can be used to
|
| map to its model.Type
|
| - |item_type| a model.Property representing the type of each element in an
|
| @@ -178,9 +180,11 @@ class Property(object):
|
| _AddProperties(self, json)
|
| if is_additional_properties:
|
| self.type_ = PropertyType.ADDITIONAL_PROPERTIES
|
| + self.compiled_type = self.type_
|
| elif '$ref' in json:
|
| self.ref_type = json['$ref']
|
| self.type_ = PropertyType.REF
|
| + self.compiled_type = self.type_
|
| elif 'enum' in json and json.get('type') == 'string':
|
| # Non-string enums (as in the case of [legalValues=(1,2)]) should fall
|
| # through to the next elif.
|
| @@ -188,6 +192,7 @@ class Property(object):
|
| for value in json['enum']:
|
| self.enum_values.append(value)
|
| self.type_ = PropertyType.ENUM
|
| + self.compiled_type = self.type_
|
| elif 'type' in json:
|
| json_type = json['type']
|
| if json_type == 'string':
|
| @@ -218,11 +223,22 @@ class Property(object):
|
| self.type_ = PropertyType.BINARY
|
| else:
|
| raise ParseException(self, 'type ' + json_type + ' not recognized')
|
| + if 'compiled_type' in json:
|
| + json_compiled_type = json['compiled_type']
|
| + if json_compiled_type == 'int64':
|
| + self.compiled_type = PropertyType.INT64
|
| + else:
|
| + # TODO(mwrosen): Support more types as necessary.
|
| + raise ParseException(self, 'type ' + json_compiled_type +
|
| + ' not recognized')
|
| + else:
|
| + self.compiled_type = self.type_
|
| elif 'choices' in json:
|
| if not json['choices'] or len(json['choices']) == 0:
|
| raise ParseException(self, 'Choices has no choices')
|
| self.choices = {}
|
| self.type_ = PropertyType.CHOICES
|
| + self.compiled_type = self.type_
|
| for choice_json in json['choices']:
|
| choice = Property(self, self.name, choice_json,
|
| from_json=from_json,
|
| @@ -236,6 +252,7 @@ class Property(object):
|
| self.value = json['value']
|
| if type(self.value) == int:
|
| self.type_ = PropertyType.INTEGER
|
| + self.compiled_type = self.type_
|
| else:
|
| # TODO(kalman): support more types as necessary.
|
| raise ParseException(
|
| @@ -287,6 +304,7 @@ class PropertyType(object):
|
| return self.name
|
|
|
| INTEGER = _Info(True, "INTEGER")
|
| + INT64 = _Info(True, "INT64")
|
| DOUBLE = _Info(True, "DOUBLE")
|
| BOOLEAN = _Info(True, "BOOLEAN")
|
| STRING = _Info(True, "STRING")
|
|
|