OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/common/json_schema/json_schema_validator.h" | 5 #include "chrome/common/json_schema/json_schema_validator.h" |
6 | 6 |
7 #include <cfloat> | 7 #include <cfloat> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 } | 93 } |
94 case Value::TYPE_STRING: | 94 case Value::TYPE_STRING: |
95 return schema::kString; | 95 return schema::kString; |
96 case Value::TYPE_DICTIONARY: | 96 case Value::TYPE_DICTIONARY: |
97 return schema::kObject; | 97 return schema::kObject; |
98 case Value::TYPE_LIST: | 98 case Value::TYPE_LIST: |
99 return schema::kArray; | 99 return schema::kArray; |
100 default: | 100 default: |
101 NOTREACHED() << "Unexpected value type: " << value->GetType(); | 101 NOTREACHED() << "Unexpected value type: " << value->GetType(); |
102 return ""; | 102 return std::string(); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 // static | 106 // static |
107 std::string JSONSchemaValidator::FormatErrorMessage(const std::string& format, | 107 std::string JSONSchemaValidator::FormatErrorMessage(const std::string& format, |
108 const std::string& s1) { | 108 const std::string& s1) { |
109 std::string ret_val = format; | 109 std::string ret_val = format; |
110 ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); | 110 ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); |
111 return ret_val; | 111 return ret_val; |
112 } | 112 } |
(...skipping 27 matching lines...) Expand all Loading... |
140 | 140 |
141 CHECK(types_.find(id) == types_.end()); | 141 CHECK(types_.find(id) == types_.end()); |
142 types_[id] = type; | 142 types_[id] = type; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 JSONSchemaValidator::~JSONSchemaValidator() {} | 146 JSONSchemaValidator::~JSONSchemaValidator() {} |
147 | 147 |
148 bool JSONSchemaValidator::Validate(const Value* instance) { | 148 bool JSONSchemaValidator::Validate(const Value* instance) { |
149 errors_.clear(); | 149 errors_.clear(); |
150 Validate(instance, schema_root_, ""); | 150 Validate(instance, schema_root_, std::string()); |
151 return errors_.empty(); | 151 return errors_.empty(); |
152 } | 152 } |
153 | 153 |
154 void JSONSchemaValidator::Validate(const Value* instance, | 154 void JSONSchemaValidator::Validate(const Value* instance, |
155 const DictionaryValue* schema, | 155 const DictionaryValue* schema, |
156 const std::string& path) { | 156 const std::string& path) { |
157 // If this schema defines itself as reference type, save it in this.types. | 157 // If this schema defines itself as reference type, save it in this.types. |
158 std::string id; | 158 std::string id; |
159 if (schema->GetString(schema::kId, &id)) { | 159 if (schema->GetString(schema::kId, &id)) { |
160 TypeMap::iterator iter = types_.find(id); | 160 TypeMap::iterator iter = types_.find(id); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 487 |
488 if (*additional_properties_schema) { | 488 if (*additional_properties_schema) { |
489 std::string additional_properties_type(schema::kAny); | 489 std::string additional_properties_type(schema::kAny); |
490 CHECK((*additional_properties_schema)->GetString( | 490 CHECK((*additional_properties_schema)->GetString( |
491 schema::kType, &additional_properties_type)); | 491 schema::kType, &additional_properties_type)); |
492 return additional_properties_type == schema::kAny; | 492 return additional_properties_type == schema::kAny; |
493 } else { | 493 } else { |
494 return default_allow_additional_properties_; | 494 return default_allow_additional_properties_; |
495 } | 495 } |
496 } | 496 } |
OLD | NEW |