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),
407 m_is_exclusive(false) {
411 return (m_has_exclusive && m_is_exclusive) ? value < *m_limit
416 schema->
AddValue(
"maximum", m_limit->Clone());
417 if (m_has_exclusive) {
418 schema->
Add(
"exclusiveMaximum", m_is_exclusive);
423 std::auto_ptr<const JsonNumber> m_limit;
424 bool m_has_exclusive, m_is_exclusive;
439 m_has_exclusive(true),
440 m_is_exclusive(is_exclusive) {
449 m_has_exclusive(false),
450 m_is_exclusive(false) {
454 return (m_has_exclusive && m_is_exclusive) ? value > *m_limit
459 schema->
AddValue(
"minimum", m_limit->Clone());
460 if (m_has_exclusive) {
461 schema->
Add(
"exclusiveMinimum", m_is_exclusive);
466 std::auto_ptr<const JsonNumber> m_limit;
467 bool m_has_exclusive, m_is_exclusive;
496 std::vector<NumberConstraint*> m_constraints;
530 : max_properties(-1),
532 has_required_properties(
false),
533 has_allow_additional_properties(
false),
534 allow_additional_properties(
false) {
537 void SetRequiredProperties(
538 const std::set<std::string> &required_properties_arg) {
539 required_properties = required_properties_arg;
540 has_required_properties =
true;
543 void SetAdditionalProperties(
bool allow_additional) {
544 has_allow_additional_properties =
true;
545 allow_additional_properties = allow_additional;
549 unsigned int min_properties;
550 bool has_required_properties;
551 std::set<std::string> required_properties;
552 bool has_allow_additional_properties;
553 bool allow_additional_properties;
594 const std::set<std::string> &properties);
598 void VisitProperty(
const std::string &property,
const JsonValue &value);
601 typedef std::set<std::string> StringSet;
602 typedef std::map<std::string, ValidatorInterface*> PropertyValidators;
603 typedef std::map<std::string, ValidatorInterface*> SchemaDependencies;
604 typedef std::map<std::string, StringSet> PropertyDependencies;
608 PropertyValidators m_property_validators;
609 std::auto_ptr<ValidatorInterface> m_additional_property_validator;
610 PropertyDependencies m_property_dependencies;
611 SchemaDependencies m_schema_dependencies;
613 StringSet m_seen_properties;
632 : m_validator(validator) {
637 m_validator_list(*validators) {
645 const ValidatorList& Validators()
const {
return m_validator_list; }
648 std::auto_ptr<ValidatorInterface> m_validator;
651 DISALLOW_COPY_AND_ASSIGN(
Items);
660 : m_allowed(allow_additional),
666 m_validator(validator) {
670 bool AllowAdditional()
const {
return m_allowed; }
674 std::auto_ptr<ValidatorInterface> m_validator;
683 unique_items(
false) {
687 unsigned int min_items;
706 typedef std::deque<ValidatorInterface*> ValidatorQueue;
708 const std::auto_ptr<Items> m_items;
709 const std::auto_ptr<AdditionalItems> m_additional_items;
713 std::auto_ptr<WildcardValidator> m_wildcard_validator;
733 ValidatorQueue m_item_validators;
736 template <
typename T>
737 void ValidateItem(
const T &item);
743 ArrayElementValidator* ConstructElementValidator()
const;
796 void Visit(
const JsonInt &value) {
809 std::string m_keyword;
814 virtual void Validate(
const JsonValue &value) = 0;
889 m_validator(validator) {
924 void Visit(
const JsonInt &value) {
937 std::auto_ptr<ValidatorInterface> m_validator;
956 bool HasDefinitions()
const {
return !m_validators.empty(); }
959 typedef std::map<std::string, ValidatorInterface*> SchemaMap;
961 SchemaMap m_validators;
977 std::string SchemaURI()
const;
997 std::string m_schema_uri;
998 std::auto_ptr<ValidatorInterface> m_root_validator;
999 std::auto_ptr<SchemaDefinitions> m_schema_defs;
1011 #endif // INCLUDE_OLA_WEB_JSONSCHEMA_H_