29 #ifndef INCLUDE_OLA_WEB_JSONSCHEMA_H_
30 #define INCLUDE_OLA_WEB_JSONSCHEMA_H_
51 class SchemaDefinitions;
68 virtual bool IsValid()
const = 0;
82 virtual void SetSchema(
const std::string &schema) = 0;
87 virtual void SetId(
const std::string &
id) = 0;
92 virtual void SetTitle(
const std::string &title) = 0;
131 virtual bool IsValid()
const {
return m_is_valid; }
137 virtual void Visit(
const JsonBool&) {
141 virtual void Visit(
const JsonNull&) {
145 virtual void Visit(
const JsonRawValue&) {
149 virtual void Visit(
const JsonObject&) {
153 virtual void Visit(
const JsonArray&) {
157 virtual void Visit(
const JsonUInt&) {
161 virtual void Visit(
const JsonUInt64&) {
165 virtual void Visit(
const JsonInt&) {
169 virtual void Visit(
const JsonInt64&) {
173 virtual void Visit(
const JsonDouble&) {
182 void SetSchema(
const std::string &schema);
187 void SetId(
const std::string &
id);
192 void SetTitle(
const std::string &title);
220 std::string m_schema;
223 std::string m_description;
224 std::auto_ptr<const JsonValue> m_default_value;
225 std::vector<const JsonValue*> m_enums;
227 bool CheckEnums(
const JsonValue &value);
230 virtual void ExtendSchema(JsonObject *schema)
const {
257 const std::string &schema);
269 void Visit(
const JsonInt &value);
275 void SetSchema(
const std::string &schema);
276 void SetId(
const std::string &
id);
277 void SetTitle(
const std::string &title);
284 const std::string m_schema;
287 template <
typename T>
288 void Validate(
const T &value);
302 unsigned int min_length;
317 const Options m_options;
331 void Visit(
const JsonBool &value) { m_is_valid = CheckEnums(value); }
344 void Visit(
const JsonNull &value) { m_is_valid = CheckEnums(value); }
358 virtual bool IsValid(
const JsonNumber &value) = 0;
360 virtual void ExtendSchema(
JsonObject *schema)
const = 0;
369 : m_multiple_of(value) {
377 schema->
AddValue(
"multipleOf", m_multiple_of->Clone());
381 std::auto_ptr<const JsonNumber> m_multiple_of;
396 m_has_exclusive(true),
397 m_is_exclusive(is_exclusive) {
406 m_has_exclusive(false) {
410 return (m_has_exclusive && m_is_exclusive) ? value < *m_limit
415 schema->
AddValue(
"maximum", m_limit->Clone());
416 if (m_has_exclusive) {
417 schema->
Add(
"exclusiveMaximum", m_is_exclusive);
422 std::auto_ptr<const JsonNumber> m_limit;
423 bool m_has_exclusive, m_is_exclusive;
438 m_has_exclusive(true),
439 m_is_exclusive(is_exclusive) {
448 m_has_exclusive(false) {
452 return (m_has_exclusive && m_is_exclusive) ? value > *m_limit
457 schema->
AddValue(
"minimum", m_limit->Clone());
458 if (m_has_exclusive) {
459 schema->
Add(
"exclusiveMinimum", m_is_exclusive);
464 std::auto_ptr<const JsonNumber> m_limit;
465 bool m_has_exclusive, m_is_exclusive;
494 std::vector<NumberConstraint*> m_constraints;
528 : max_properties(-1),
530 has_required_properties(
false),
531 has_allow_additional_properties(
false) {
534 void SetRequiredProperties(
535 const std::set<std::string> &required_properties_arg) {
536 required_properties = required_properties_arg;
537 has_required_properties =
true;
540 void SetAdditionalProperties(
bool allow_additional) {
541 has_allow_additional_properties =
true;
542 allow_additional_properties = allow_additional;
546 unsigned int min_properties;
547 bool has_required_properties;
548 std::set<std::string> required_properties;
549 bool has_allow_additional_properties;
550 bool allow_additional_properties;
591 const std::set<std::string> &properties);
595 void VisitProperty(
const std::string &property,
const JsonValue &value);
598 typedef std::set<std::string> StringSet;
599 typedef std::map<std::string, ValidatorInterface*> PropertyValidators;
600 typedef std::map<std::string, ValidatorInterface*> SchemaDependencies;
601 typedef std::map<std::string, StringSet> PropertyDependencies;
605 PropertyValidators m_property_validators;
606 std::auto_ptr<ValidatorInterface> m_additional_property_validator;
607 PropertyDependencies m_property_dependencies;
608 SchemaDependencies m_schema_dependencies;
610 StringSet m_seen_properties;
629 : m_validator(validator) {
634 m_validator_list(*validators) {
642 const ValidatorList& Validators()
const {
return m_validator_list; }
645 std::auto_ptr<ValidatorInterface> m_validator;
648 DISALLOW_COPY_AND_ASSIGN(
Items);
657 : m_allowed(allow_additional),
663 m_validator(validator) {
667 bool AllowAdditional()
const {
return m_allowed; }
671 std::auto_ptr<ValidatorInterface> m_validator;
680 unique_items(
false) {
684 unsigned int min_items;
703 typedef std::deque<ValidatorInterface*> ValidatorQueue;
705 const std::auto_ptr<Items> m_items;
706 const std::auto_ptr<AdditionalItems> m_additional_items;
710 std::auto_ptr<WildcardValidator> m_wildcard_validator;
730 ValidatorQueue m_item_validators;
733 template <
typename T>
734 void ValidateItem(
const T &item);
740 ArrayElementValidator* ConstructElementValidator()
const;
793 void Visit(
const JsonInt &value) {
806 std::string m_keyword;
811 virtual void Validate(
const JsonValue &value) = 0;
886 m_validator(validator) {
921 void Visit(
const JsonInt &value) {
934 std::auto_ptr<ValidatorInterface> m_validator;
953 bool HasDefinitions()
const {
return !m_validators.empty(); }
956 typedef std::map<std::string, ValidatorInterface*> SchemaMap;
958 SchemaMap m_validators;
974 std::string SchemaURI()
const;
994 std::string m_schema_uri;
995 std::auto_ptr<ValidatorInterface> m_root_validator;
996 std::auto_ptr<SchemaDefinitions> m_schema_defs;
1008 #endif // INCLUDE_OLA_WEB_JSONSCHEMA_H_