Lines Matching refs:schema
5 #include "components/policy/core/common/schema.h"
23 namespace schema = json_schema_constants;
35 // Maps schema "id" attributes to the corresponding SchemaNode index.
71 { schema::kArray, base::Value::TYPE_LIST },
72 { schema::kBoolean, base::Value::TYPE_BOOLEAN },
73 { schema::kInteger, base::Value::TYPE_INTEGER },
74 { schema::kNull, base::Value::TYPE_NULL },
75 { schema::kNumber, base::Value::TYPE_DOUBLE },
76 { schema::kObject, base::Value::TYPE_DICTIONARY },
77 { schema::kString, base::Value::TYPE_STRING },
138 // Contains the internal data representation of a Schema. This can either wrap
139 // a SchemaData owned elsewhere (currently used to wrap the Chrome schema, which
141 class Schema::InternalStorage
147 const base::DictionaryValue& schema,
153 return schema(0);
156 const SchemaNode* schema(int index) const {
191 // of |schema|.
192 static void DetermineStorageSizes(const base::DictionaryValue& schema,
195 // Parses the JSON schema in |schema|.
197 // If |schema| has a "$ref" attribute then a pending reference is appended
201 // in |schema_nodes_|. If the |schema| contains an "id" then that ID is mapped
204 // If |schema| is invalid then |error| gets the error reason and false is
206 bool Parse(const base::DictionaryValue& schema,
214 bool ParseDictionary(const base::DictionaryValue& schema,
222 bool ParseList(const base::DictionaryValue& schema,
228 bool ParseEnum(const base::DictionaryValue& schema,
233 bool ParseRangedInt(const base::DictionaryValue& schema,
237 bool ParseStringPattern(const base::DictionaryValue& schema,
265 Schema::InternalStorage::InternalStorage()
268 Schema::InternalStorage::~InternalStorage() {}
271 scoped_refptr<const Schema::InternalStorage> Schema::InternalStorage::Wrap(
284 scoped_refptr<const Schema::InternalStorage>
285 Schema::InternalStorage::ParseSchema(const base::DictionaryValue& schema,
292 DetermineStorageSizes(schema, &sizes);
306 if (!storage->Parse(schema, &root_index, &id_map, &reference_list, error))
310 *error = "The main schema can't have a $ref";
325 *error = "Failed to parse the schema due to a Chrome bug. Please file a "
343 re2::RE2* Schema::InternalStorage::CompileRegex(
355 void Schema::InternalStorage::DetermineStorageSizes(
356 const base::DictionaryValue& schema,
359 if (schema.GetString(schema::kRef, &ref_string)) {
366 if (!schema.GetString(schema::kType, &type_string) ||
368 // This schema is invalid.
376 if (schema.GetDictionary(schema::kItems, &items))
382 if (schema.GetDictionary(schema::kAdditionalProperties, &dict))
386 if (schema.GetDictionary(schema::kProperties, &properties)) {
398 if (schema.GetDictionary(schema::kPatternProperties, &pattern_properties)) {
407 } else if (schema.HasKey(schema::kEnum)) {
409 if (schema.GetList(schema::kEnum, &possible_values)) {
419 if (schema.HasKey(schema::kMinimum) || schema.HasKey(schema::kMaximum))
422 if (schema.HasKey(schema::kPattern)) {
430 bool Schema::InternalStorage::Parse(const base::DictionaryValue& schema,
436 if (schema.GetString(schema::kRef, &ref_string)) {
438 if (schema.GetString(schema::kId, &id_string)) {
447 if (!schema.GetString(schema::kType, &type_string)) {
448 *error = "The schema type must be declared.";
465 if (!ParseDictionary(schema, schema_node, id_map, reference_list, error))
468 if (!ParseList(schema, schema_node, id_map, reference_list, error))
470 } else if (schema.HasKey(schema::kEnum)) {
471 if (!ParseEnum(schema, type, schema_node, error))
473 } else if (schema.HasKey(schema::kPattern)) {
474 if (!ParseStringPattern(schema, schema_node, error))
476 } else if (schema.HasKey(schema::kMinimum) ||
477 schema.HasKey(schema::kMaximum)) {
482 if (!ParseRangedInt(schema, schema_node, error))
486 if (schema.GetString(schema::kId, &id_string)) {
497 bool Schema::InternalStorage::ParseDictionary(
498 const base::DictionaryValue& schema,
509 if (schema.GetDictionary(schema::kAdditionalProperties, &dict)) {
519 if (schema.GetDictionary(schema::kProperties, &properties)) {
529 if (schema.GetDictionary(schema::kPatternProperties, &pattern_properties))
545 if (!Parse(*dict, &property_nodes_[index].schema,
568 if (!Parse(*dict, &property_nodes_[index].schema,
585 bool Schema::InternalStorage::ParseList(const base::DictionaryValue& schema,
591 if (!schema.GetDictionary(schema::kItems, &dict)) {
592 *error = "Arrays must declare a single schema for their items.";
598 bool Schema::InternalStorage::ParseEnum(const base::DictionaryValue& schema,
603 if (!schema.GetList(schema::kEnum, &possible_values)) {
649 bool Schema::InternalStorage::ParseRangedInt(
650 const base::DictionaryValue& schema,
656 if (schema.GetInteger(schema::kMinimum, &value))
658 if (schema.GetInteger(schema::kMaximum, &value))
671 bool Schema::InternalStorage::ParseStringPattern(
672 const base::DictionaryValue& schema,
676 if (!schema.GetString(schema::kPattern, &pattern)) {
677 *error = "Schema pattern must be a string.";
697 bool Schema::InternalStorage::ResolveReferences(
713 Schema::Iterator::Iterator(const scoped_refptr<const InternalStorage>& storage,
719 Schema::Iterator::Iterator(const Iterator& iterator)
724 Schema::Iterator::~Iterator() {}
726 Schema::Iterator& Schema::Iterator::operator=(const Iterator& iterator) {
733 bool Schema::Iterator::IsAtEnd() const {
737 void Schema::Iterator::Advance() {
741 const char* Schema::Iterator::key() const {
745 Schema Schema::Iterator::schema() const {
746 return Schema(storage_, storage_->schema(it_->schema));
749 Schema::Schema() : node_(NULL) {}
751 Schema::Schema(const scoped_refptr<const InternalStorage>& storage,
755 Schema::Schema(const Schema& schema)
756 : storage_(schema.storage_), node_(schema.node_) {}
758 Schema::~Schema() {}
760 Schema& Schema::operator=(const Schema& schema) {
761 storage_ = schema.storage_;
762 node_ = schema.node_;
767 Schema Schema::Wrap(const SchemaData* data) {
769 return Schema(storage, storage->root_node());
772 bool Schema::Validate(const base::Value& value,
777 SchemaErrorFound(error_path, error, "The schema is invalid.");
790 error_path, error, "The value type doesn't match the schema type.");
853 bool Schema::Normalize(base::Value* value,
859 SchemaErrorFound(error_path, error, "The schema is invalid.");
872 error_path, error, "The value type doesn't match the schema type.");
951 Schema Schema::Parse(const std::string& content, std::string* error) {
952 // Validate as a generic JSON schema, and ignore unknown attributes; they
953 // may become used in a future version of the schema format.
957 return Schema();
961 if (!dict->GetString(schema::kType, &string_value) ||
962 string_value != schema::kObject) {
964 "The main schema must have a type attribute with \"object\" value.";
965 return Schema();
969 if (dict->HasKey(schema::kAdditionalProperties) ||
970 dict->HasKey(schema::kPatternProperties)) {
972 "supported at the main schema.";
973 return Schema();
979 return Schema();
980 return Schema(storage, storage->root_node());
983 base::Value::Type Schema::type() const {
988 Schema::Iterator Schema::GetPropertiesIterator() const {
1002 Schema Schema::GetKnownProperty(const std::string& key) const {
1010 return Schema(storage_, storage_->schema(it->schema));
1011 return Schema();
1014 Schema Schema::GetAdditionalProperties() const {
1019 return Schema();
1020 return Schema(storage_, storage_->schema(node->additional));
1023 SchemaList Schema::GetPatternProperties(const std::string& key) const {
1033 Schema(storage_, storage_->schema(it->schema)));
1039 Schema Schema::GetProperty(const std::string& key) const {
1040 Schema schema = GetKnownProperty(key);
1041 if (schema.valid())
1042 return schema;
1046 SchemaList Schema::GetMatchingProperties(const std::string& key) const {
1049 Schema known_property = GetKnownProperty(key);
1058 Schema additional_property = GetAdditionalProperties();
1066 Schema Schema::GetItems() const {
1070 return Schema();
1071 return Schema(storage_, storage_->schema(node_->extra));
1074 bool Schema::ValidateIntegerRestriction(int index, int value) const {
1090 bool Schema::ValidateStringRestriction(int index, const char* str) const {