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 #ifndef CHROME_COMMON_JSON_SCHEMA_JSON_SCHEMA_VALIDATOR_H_ | 5 #ifndef CHROME_COMMON_JSON_SCHEMA_JSON_SCHEMA_VALIDATOR_H_ |
6 #define CHROME_COMMON_JSON_SCHEMA_JSON_SCHEMA_VALIDATOR_H_ | 6 #define CHROME_COMMON_JSON_SCHEMA_JSON_SCHEMA_VALIDATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class DictionaryValue; | 16 class DictionaryValue; |
16 class ListValue; | 17 class ListValue; |
17 class StringValue; | 18 class StringValue; |
18 class Value; | 19 class Value; |
19 } | 20 } |
20 | 21 |
21 //============================================================================== | 22 //============================================================================== |
22 // This class implements a subset of JSON Schema. | 23 // This class implements a subset of JSON Schema. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 92 |
92 // Utility methods to format error messages. The first method can have one | 93 // Utility methods to format error messages. The first method can have one |
93 // wildcard represented by '*', which is replaced with s1. The second method | 94 // wildcard represented by '*', which is replaced with s1. The second method |
94 // can have two, which are replaced by s1 and s2. | 95 // can have two, which are replaced by s1 and s2. |
95 static std::string FormatErrorMessage(const std::string& format, | 96 static std::string FormatErrorMessage(const std::string& format, |
96 const std::string& s1); | 97 const std::string& s1); |
97 static std::string FormatErrorMessage(const std::string& format, | 98 static std::string FormatErrorMessage(const std::string& format, |
98 const std::string& s1, | 99 const std::string& s1, |
99 const std::string& s2); | 100 const std::string& s2); |
100 | 101 |
| 102 // Verifies if |schema| is a valid JSON v3 schema. When this validation passes |
| 103 // then |schema| is valid JSON that can be parsed into a DictionaryValue, |
| 104 // and that DictionaryValue can be used to build a JSONSchemaValidator. |
| 105 // Returns the parsed DictionaryValue when |schema| validated, otherwise |
| 106 // returns NULL. In that case, |error| contains an error description. |
| 107 static scoped_ptr<base::DictionaryValue> IsValidSchema( |
| 108 const std::string& schema, |
| 109 std::string* error); |
| 110 |
101 // Creates a validator for the specified schema. | 111 // Creates a validator for the specified schema. |
102 // | 112 // |
103 // NOTE: This constructor assumes that |schema| is well formed and valid. | 113 // NOTE: This constructor assumes that |schema| is well formed and valid. |
104 // Errors will result in CHECK at runtime; this constructor should not be used | 114 // Errors will result in CHECK at runtime; this constructor should not be used |
105 // with untrusted schemas. | 115 // with untrusted schemas. |
106 explicit JSONSchemaValidator(base::DictionaryValue* schema); | 116 explicit JSONSchemaValidator(base::DictionaryValue* schema); |
107 | 117 |
108 // Creates a validator for the specified schema and user-defined types. Each | 118 // Creates a validator for the specified schema and user-defined types. Each |
109 // type must be a valid JSONSchema type description with an additional "id" | 119 // type must be a valid JSONSchema type description with an additional "id" |
110 // field. Schema objects in |schema| can refer to these types with the "$ref" | 120 // field. Schema objects in |schema| can refer to these types with the "$ref" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 bool default_allow_additional_properties_; | 226 bool default_allow_additional_properties_; |
217 | 227 |
218 // Errors accumulated since the last call to Validate(). | 228 // Errors accumulated since the last call to Validate(). |
219 std::vector<Error> errors_; | 229 std::vector<Error> errors_; |
220 | 230 |
221 | 231 |
222 DISALLOW_COPY_AND_ASSIGN(JSONSchemaValidator); | 232 DISALLOW_COPY_AND_ASSIGN(JSONSchemaValidator); |
223 }; | 233 }; |
224 | 234 |
225 #endif // CHROME_COMMON_JSON_SCHEMA_JSON_SCHEMA_VALIDATOR_H_ | 235 #endif // CHROME_COMMON_JSON_SCHEMA_JSON_SCHEMA_VALIDATOR_H_ |
OLD | NEW |