Open Lighting Architecture: include/ola/web/JsonSchema.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
JsonSchema.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * JsonSchema.h
17 * A Json Schema, see json-schema.org
18 * Copyright (C) 2014 Simon Newton
19 */
20
28
29#ifndef INCLUDE_OLA_WEB_JSONSCHEMA_H_
30#define INCLUDE_OLA_WEB_JSONSCHEMA_H_
31
32#include <ola/base/Macro.h>
33#include <ola/stl/STLUtils.h>
34#include <ola/web/Json.h>
35#include <ola/web/JsonTypes.h>
36#include <deque>
37#include <map>
38#include <memory>
39#include <set>
40#include <string>
41#include <vector>
42
43namespace ola {
44namespace web {
45
50
51class SchemaDefinitions;
52
56 class ValidatorInterface : public JsonValueConstVisitorInterface {
57 public:
61 typedef std::vector<ValidatorInterface*> ValidatorList;
62
63 virtual ~ValidatorInterface() {}
64
68 virtual bool IsValid() const = 0;
69
70 // Do we need a "GetError" here?
71
77 virtual JsonObject* GetSchema() const = 0;
78
82 virtual void SetSchema(const std::string &schema) = 0;
83
87 virtual void SetId(const std::string &id) = 0;
88
92 virtual void SetTitle(const std::string &title) = 0;
93
97 virtual void SetDescription(const std::string &title) = 0;
98
104 virtual void SetDefaultValue(const JsonValue *value) = 0;
105
114 virtual const JsonValue *GetDefaultValue() const = 0;
115};
116
121 class BaseValidator : public ValidatorInterface {
122 protected:
123 explicit BaseValidator(JsonType type)
124 : m_is_valid(true),
125 m_type(type) {
126 }
127
128 public:
129 virtual ~BaseValidator();
130
131 virtual bool IsValid() const { return m_is_valid; }
132
133 virtual void Visit(const JsonString&) {
134 m_is_valid = false;
135 }
136
137 virtual void Visit(const JsonBool&) {
138 m_is_valid = false;
139 }
140
141 virtual void Visit(const JsonNull&) {
142 m_is_valid = false;
143 }
144
145 virtual void Visit(const JsonRawValue&) {
146 m_is_valid = false;
147 }
148
149 virtual void Visit(const JsonObject&) {
150 m_is_valid = false;
151 }
152
153 virtual void Visit(const JsonArray&) {
154 m_is_valid = false;
155 }
156
157 virtual void Visit(const JsonUInt&) {
158 m_is_valid = false;
159 }
160
161 virtual void Visit(const JsonUInt64&) {
162 m_is_valid = false;
163 }
164
165 virtual void Visit(const JsonInt&) {
166 m_is_valid = false;
167 }
168
169 virtual void Visit(const JsonInt64&) {
170 m_is_valid = false;
171 }
172
173 virtual void Visit(const JsonDouble&) {
174 m_is_valid = false;
175 }
176
177 virtual JsonObject* GetSchema() const;
178
182 void SetSchema(const std::string &schema);
183
187 void SetId(const std::string &id);
188
192 void SetTitle(const std::string &title);
193
197 void SetDescription(const std::string &title);
198
203 void SetDefaultValue(const JsonValue *value);
204
209 const JsonValue *GetDefaultValue() const;
210
215 void AddEnumValue(const JsonValue *value);
216
217 protected:
218 bool m_is_valid;
219 JsonType m_type;
220 std::string m_schema;
221 std::string m_id;
222 std::string m_title;
223 std::string m_description;
224 std::auto_ptr<const JsonValue> m_default_value;
225 std::vector<const JsonValue*> m_enums;
226
227 bool CheckEnums(const JsonValue &value);
228
229 // Child classes can hook in here to extend the schema.
230 virtual void ExtendSchema(JsonObject *schema) const {
231 (void) schema;
232 }
233};
234
239 class WildcardValidator : public BaseValidator {
240 public:
241 WildcardValidator() : BaseValidator(JSON_UNDEFINED) {}
242
243 bool IsValid() const { return true; }
244};
245
249 class ReferenceValidator : public ValidatorInterface {
250 public:
256 ReferenceValidator(const SchemaDefinitions *definitions,
257 const std::string &schema);
258
259 bool IsValid() const;
260
261 void Visit(const JsonString &value);
262 void Visit(const JsonBool &value);
263 void Visit(const JsonNull &value);
264 void Visit(const JsonRawValue &value);
265 void Visit(const JsonObject &value);
266 void Visit(const JsonArray &value);
267 void Visit(const JsonUInt &value);
268 void Visit(const JsonUInt64 &value);
269 void Visit(const JsonInt &value);
270 void Visit(const JsonInt64 &value);
271 void Visit(const JsonDouble &value);
272
273 JsonObject* GetSchema() const;
274
275 void SetSchema(const std::string &schema);
276 void SetId(const std::string &id);
277 void SetTitle(const std::string &title);
278 void SetDescription(const std::string &title);
279 void SetDefaultValue(const JsonValue *value);
280 const JsonValue *GetDefaultValue() const;
281
282 private:
283 const SchemaDefinitions *m_definitions;
284 const std::string m_schema;
285 ValidatorInterface *m_validator;
286
287 template <typename T>
288 void Validate(const T &value);
289};
290
294 class StringValidator : public BaseValidator {
295 public:
296 struct Options {
297 Options()
298 : min_length(0),
299 max_length(-1) {
300 }
301
302 unsigned int min_length;
303 int max_length;
304 // Formats & Regexes aren't supported.
305 // std::string pattern
306 // std::string format
307 };
308
309 explicit StringValidator(const Options &options)
310 : BaseValidator(JSON_STRING),
311 m_options(options) {
312 }
313
314 void Visit(const JsonString &str);
315
316 private:
317 const Options m_options;
318
319 void ExtendSchema(JsonObject *schema) const;
320
321 StringValidator(const StringValidator &) = delete;
322 const StringValidator &operator=(const StringValidator &) = delete;
323};
324
328 class BoolValidator : public BaseValidator {
329 public:
330 BoolValidator() : BaseValidator(JSON_BOOLEAN) {}
331
332 void Visit(const JsonBool &value) { m_is_valid = CheckEnums(value); }
333
334 private:
335 BoolValidator(const BoolValidator &) = delete;
336 const BoolValidator &operator=(const BoolValidator &) = delete;
337};
338
342 class NullValidator : public BaseValidator {
343 public:
344 NullValidator() : BaseValidator(JSON_NULL) {}
345
346 void Visit(const JsonNull &value) { m_is_valid = CheckEnums(value); }
347
348 private:
349 NullValidator(const NullValidator &) = delete;
350 const NullValidator &operator=(const NullValidator &) = delete;
351};
352
357 class NumberConstraint {
358 public:
359 virtual ~NumberConstraint() {}
360
361 virtual bool IsValid(const JsonNumber &value) = 0;
362
363 virtual void ExtendSchema(JsonObject *schema) const = 0;
364};
365
369 class MultipleOfConstraint : public NumberConstraint {
370 public:
371 explicit MultipleOfConstraint(const JsonNumber *value)
372 : m_multiple_of(value) {
373 }
374
375 bool IsValid(const JsonNumber &value) {
376 return value.MultipleOf(*m_multiple_of);
377 }
378
379 void ExtendSchema(JsonObject *schema) const {
380 schema->AddValue("multipleOf", m_multiple_of->Clone());
381 }
382
383 private:
384 std::auto_ptr<const JsonNumber> m_multiple_of;
385};
386
390 class MaximumConstraint : public NumberConstraint {
391 public:
397 MaximumConstraint(const JsonNumber *limit, bool is_exclusive)
398 : m_limit(limit),
399 m_has_exclusive(true),
400 m_is_exclusive(is_exclusive) {
401 }
402
407 explicit MaximumConstraint(const JsonNumber *limit)
408 : m_limit(limit),
409 m_has_exclusive(false),
410 m_is_exclusive(false) {
411 }
412
413 bool IsValid(const JsonNumber &value) {
414 return (m_has_exclusive && m_is_exclusive) ? value < *m_limit
415 : value <= *m_limit;
416 }
417
418 void ExtendSchema(JsonObject *schema) const {
419 schema->AddValue("maximum", m_limit->Clone());
420 if (m_has_exclusive) {
421 schema->Add("exclusiveMaximum", m_is_exclusive);
422 }
423 }
424
425 private:
426 std::auto_ptr<const JsonNumber> m_limit;
427 bool m_has_exclusive, m_is_exclusive;
428};
429
433 class MinimumConstraint : public NumberConstraint {
434 public:
440 MinimumConstraint(const JsonNumber *limit, bool is_exclusive)
441 : m_limit(limit),
442 m_has_exclusive(true),
443 m_is_exclusive(is_exclusive) {
444 }
445
450 explicit MinimumConstraint(const JsonNumber *limit)
451 : m_limit(limit),
452 m_has_exclusive(false),
453 m_is_exclusive(false) {
454 }
455
456 bool IsValid(const JsonNumber &value) {
457 return (m_has_exclusive && m_is_exclusive) ? value > *m_limit
458 : value >= *m_limit;
459 }
460
461 void ExtendSchema(JsonObject *schema) const {
462 schema->AddValue("minimum", m_limit->Clone());
463 if (m_has_exclusive) {
464 schema->Add("exclusiveMinimum", m_is_exclusive);
465 }
466 }
467
468 private:
469 std::auto_ptr<const JsonNumber> m_limit;
470 bool m_has_exclusive, m_is_exclusive;
471};
472
476 class IntegerValidator : public BaseValidator {
477 public:
478 IntegerValidator() : BaseValidator(JSON_INTEGER) {}
479 virtual ~IntegerValidator();
480
485 void AddConstraint(NumberConstraint *constraint);
486
487 void Visit(const JsonUInt&);
488 void Visit(const JsonInt&);
489 void Visit(const JsonUInt64&);
490 void Visit(const JsonInt64&);
491 virtual void Visit(const JsonDouble&);
492
493 protected:
494 explicit IntegerValidator(JsonType type) : BaseValidator(type) {}
495
496 void CheckValue(const JsonNumber &value);
497
498 private:
499 std::vector<NumberConstraint*> m_constraints;
500
501 void ExtendSchema(JsonObject *schema) const;
502
503 IntegerValidator(const IntegerValidator &) = delete;
504 const IntegerValidator &operator=(const IntegerValidator &) = delete;
505};
506
507
513 class NumberValidator : public IntegerValidator {
514 public:
515 NumberValidator() : IntegerValidator(JSON_NUMBER) {}
516
517 void Visit(const JsonDouble&);
518
519 private:
520 NumberValidator(const NumberValidator &) = delete;
521 const NumberValidator &operator=(const NumberValidator &) = delete;
522};
523
531 class ObjectValidator : public BaseValidator, JsonObjectPropertyVisitor {
532 public:
533 struct Options {
534 Options()
535 : max_properties(-1),
536 min_properties(0),
537 has_required_properties(false),
538 has_allow_additional_properties(false),
539 allow_additional_properties(false) {
540 }
541
542 void SetRequiredProperties(
543 const std::set<std::string> &required_properties_arg) {
544 required_properties = required_properties_arg;
545 has_required_properties = true;
546 }
547
548 void SetAdditionalProperties(bool allow_additional) {
549 has_allow_additional_properties = true;
550 allow_additional_properties = allow_additional;
551 }
552
553 int max_properties;
554 unsigned int min_properties;
555 bool has_required_properties;
556 std::set<std::string> required_properties;
557 bool has_allow_additional_properties;
558 bool allow_additional_properties;
559 };
560
561 explicit ObjectValidator(const Options &options);
562 ~ObjectValidator();
563
569 void AddValidator(const std::string &property, ValidatorInterface *validator);
570
575 void SetAdditionalValidator(ValidatorInterface *validator);
576
586 void AddSchemaDependency(const std::string &property,
587 ValidatorInterface *validator);
588
598 void AddPropertyDependency(const std::string &property,
599 const std::set<std::string> &properties);
600
601 void Visit(const JsonObject &obj);
602
603 void VisitProperty(const std::string &property, const JsonValue &value);
604
605 private:
606 typedef std::set<std::string> StringSet;
607 typedef std::map<std::string, ValidatorInterface*> PropertyValidators;
608 typedef std::map<std::string, ValidatorInterface*> SchemaDependencies;
609 typedef std::map<std::string, StringSet> PropertyDependencies;
610
611 const Options m_options;
612
613 PropertyValidators m_property_validators;
614 std::auto_ptr<ValidatorInterface> m_additional_property_validator;
615 PropertyDependencies m_property_dependencies;
616 SchemaDependencies m_schema_dependencies;
617
618 StringSet m_seen_properties;
619
620 void ExtendSchema(JsonObject *schema) const;
621
622 ObjectValidator(const ObjectValidator &) = delete;
623 const ObjectValidator &operator=(const ObjectValidator &) = delete;
624};
625
629 class ArrayValidator : public BaseValidator {
630 public:
635 class Items {
636 public:
637 explicit Items(ValidatorInterface *validator)
638 : m_validator(validator) {
639 }
640
641 explicit Items(ValidatorList *validators)
642 : m_validator(NULL),
643 m_validator_list(*validators) {
644 }
645
646 ~Items() {
647 STLDeleteElements(&m_validator_list);
648 }
649
650 ValidatorInterface* Validator() const { return m_validator.get(); }
651 const ValidatorList& Validators() const { return m_validator_list; }
652
653 private:
654 std::auto_ptr<ValidatorInterface> m_validator;
655 ValidatorList m_validator_list;
656
657 Items(const Items &) = delete;
658 const Items &operator=(const Items &) = delete;
659 };
660
664 class AdditionalItems {
665 public:
666 explicit AdditionalItems(bool allow_additional)
667 : m_allowed(allow_additional),
668 m_validator(NULL) {
669 }
670
671 explicit AdditionalItems(ValidatorInterface *validator)
672 : m_allowed(true),
673 m_validator(validator) {
674 }
675
676 ValidatorInterface* Validator() const { return m_validator.get(); }
677 bool AllowAdditional() const { return m_allowed; }
678
679 private:
680 bool m_allowed;
681 std::auto_ptr<ValidatorInterface> m_validator;
682
683 AdditionalItems(const AdditionalItems &) = delete;
684 const AdditionalItems &operator=(const AdditionalItems &) = delete;
685 };
686
687 struct Options {
688 Options()
689 : max_items(-1),
690 min_items(0),
691 unique_items(false) {
692 }
693
694 int max_items;
695 unsigned int min_items;
696 bool unique_items;
697 };
698
706 ArrayValidator(Items *items, AdditionalItems *additional_items,
707 const Options &options);
708
709 ~ArrayValidator();
710
711 void Visit(const JsonArray &array);
712
713 private:
714 typedef std::deque<ValidatorInterface*> ValidatorQueue;
715
716 const std::auto_ptr<Items> m_items;
717 const std::auto_ptr<AdditionalItems> m_additional_items;
718 const Options m_options;
719
720 // This is used if items is missing, or if additionalItems is true.
721 std::auto_ptr<WildcardValidator> m_wildcard_validator;
722
723 class ArrayElementValidator : public BaseValidator {
724 public:
725 ArrayElementValidator(const ValidatorList &validators,
726 ValidatorInterface *default_validator);
727
728 void Visit(const JsonString&);
729 void Visit(const JsonBool&);
730 void Visit(const JsonNull&);
731 void Visit(const JsonRawValue&);
732 void Visit(const JsonObject&);
733 void Visit(const JsonArray &array);
734 void Visit(const JsonUInt&);
735 void Visit(const JsonUInt64&);
736 void Visit(const JsonInt&);
737 void Visit(const JsonInt64&);
738 void Visit(const JsonDouble&);
739
740 private:
741 ValidatorQueue m_item_validators;
742 ValidatorInterface *m_default_validator;
743
744 template <typename T>
745 void ValidateItem(const T &item);
746
747 ArrayElementValidator(const ArrayElementValidator &) = delete;
748 const ArrayElementValidator &operator=(const ArrayElementValidator &) = delete;
749 };
750
751 void ExtendSchema(JsonObject *schema) const;
752 ArrayElementValidator* ConstructElementValidator() const;
753
754 ArrayValidator(const ArrayValidator &) = delete;
755 const ArrayValidator &operator=(const ArrayValidator &) = delete;
756};
757
758
763 class ConjunctionValidator : public BaseValidator {
764 public:
771 ConjunctionValidator(const std::string &keyword, ValidatorList *validators);
772 virtual ~ConjunctionValidator();
773
774 void Visit(const JsonString &value) {
775 Validate(value);
776 }
777
778 void Visit(const JsonBool &value) {
779 Validate(value);
780 }
781
782 void Visit(const JsonNull &value) {
783 Validate(value);
784 }
785
786 void Visit(const JsonRawValue &value) {
787 Validate(value);
788 }
789
790 void Visit(const JsonObject &value) {
791 Validate(value);
792 }
793
794 void Visit(const JsonArray &value) {
795 Validate(value);
796 }
797
798 void Visit(const JsonUInt &value) {
799 Validate(value);
800 }
801
802 void Visit(const JsonUInt64 &value) {
803 Validate(value);
804 }
805
806 void Visit(const JsonInt &value) {
807 Validate(value);
808 }
809
810 void Visit(const JsonInt64 &value) {
811 Validate(value);
812 }
813
814 void Visit(const JsonDouble &value) {
815 Validate(value);
816 }
817
818 protected:
819 std::string m_keyword;
820 ValidatorList m_validators;
821
822 void ExtendSchema(JsonObject *schema) const;
823
824 virtual void Validate(const JsonValue &value) = 0;
825};
826
830 class AllOfValidator : public ConjunctionValidator {
831 public:
837 explicit AllOfValidator(ValidatorList *validators)
838 : ConjunctionValidator("allOf", validators) {
839 }
840
841 protected:
842 void Validate(const JsonValue &value);
843
844 private:
845 AllOfValidator(const AllOfValidator &) = delete;
846 const AllOfValidator &operator=(const AllOfValidator &) = delete;
847};
848
853 class AnyOfValidator : public ConjunctionValidator {
854 public:
860 explicit AnyOfValidator(ValidatorList *validators)
861 : ConjunctionValidator("anyOf", validators) {
862 }
863
864 protected:
865 void Validate(const JsonValue &value);
866
867 private:
868 AnyOfValidator(const AnyOfValidator &) = delete;
869 const AnyOfValidator &operator=(const AnyOfValidator &) = delete;
870};
871
876 class OneOfValidator : public ConjunctionValidator {
877 public:
883 explicit OneOfValidator(ValidatorList *validators)
884 : ConjunctionValidator("oneOf", validators) {
885 }
886
887 protected:
888 void Validate(const JsonValue &value);
889
890 private:
891 OneOfValidator(const OneOfValidator &) = delete;
892 const OneOfValidator &operator=(const OneOfValidator &) = delete;
893};
894
898 class NotValidator : public BaseValidator {
899 public:
900 explicit NotValidator(ValidatorInterface *validator)
901 : BaseValidator(JSON_UNDEFINED),
902 m_validator(validator) {
903 }
904
905 void Visit(const JsonString &value) {
906 Validate(value);
907 }
908
909 void Visit(const JsonBool &value) {
910 Validate(value);
911 }
912
913 void Visit(const JsonNull &value) {
914 Validate(value);
915 }
916
917 void Visit(const JsonRawValue &value) {
918 Validate(value);
919 }
920
921 void Visit(const JsonObject &value) {
922 Validate(value);
923 }
924
925 void Visit(const JsonArray &value) {
926 Validate(value);
927 }
928
929 void Visit(const JsonUInt &value) {
930 Validate(value);
931 }
932
933 void Visit(const JsonUInt64 &value) {
934 Validate(value);
935 }
936
937 void Visit(const JsonInt &value) {
938 Validate(value);
939 }
940
941 void Visit(const JsonInt64 &value) {
942 Validate(value);
943 }
944
945 void Visit(const JsonDouble &value) {
946 Validate(value);
947 }
948
949 private:
950 std::auto_ptr<ValidatorInterface> m_validator;
951
952 void Validate(const JsonValue &value);
953
954 void ExtendSchema(JsonObject *schema) const;
955
956 NotValidator(const NotValidator &) = delete;
957 const NotValidator &operator=(const NotValidator &) = delete;
958};
959
960 class SchemaDefinitions {
961 public:
962 SchemaDefinitions() {}
963 ~SchemaDefinitions();
964
965 void Add(const std::string &schema_name, ValidatorInterface *validator);
966 ValidatorInterface *Lookup(const std::string &schema_name) const;
967
968 void AddToJsonObject(JsonObject *json) const;
969
970 bool HasDefinitions() const { return !m_validators.empty(); }
971
972 private:
973 typedef std::map<std::string, ValidatorInterface*> SchemaMap;
974
975 SchemaMap m_validators;
976
977 SchemaDefinitions(const SchemaDefinitions &) = delete;
978 const SchemaDefinitions &operator=(const SchemaDefinitions &) = delete;
979};
980
981
985 class JsonSchema {
986 public:
987 ~JsonSchema() {}
988
989 /*
990 * @brief The URI which defines which version of the schema this is.
991 */
992 std::string SchemaURI() const;
993
997 bool IsValid(const JsonValue &value);
998
1002 const JsonObject* AsJson() const;
1003
1008 static JsonSchema* FromString(const std::string& schema_string,
1009 std::string *error);
1010
1011 private:
1012 std::string m_schema_uri;
1013 std::auto_ptr<ValidatorInterface> m_root_validator;
1014 std::auto_ptr<SchemaDefinitions> m_schema_defs;
1015
1016 JsonSchema(const std::string &schema_url,
1017 ValidatorInterface *root_validator,
1018 SchemaDefinitions *schema_defs);
1019
1020 JsonSchema(const JsonSchema &) = delete;
1021 const JsonSchema &operator=(const JsonSchema &) = delete;
1022};
1023
1025} // namespace web
1026} // namespace ola
1027#endif // INCLUDE_OLA_WEB_JSONSCHEMA_H_
Json.h
Basic data types used to represent elements in a JSON document.
JsonTypes.h
Enums used to identfy JSON types.
Macro.h
Helper macros.
STLUtils.h
Helper functions for STL classes.
ola::web::AllOfValidator
A validator which ensures all child validators pass (allOf).
Definition JsonSchema.h:830
ola::web::AllOfValidator::AllOfValidator
AllOfValidator(ValidatorList *validators)
Definition JsonSchema.h:837
ola::web::AnyOfValidator
A validator which ensures at least one of the child validators pass (anyOf).
Definition JsonSchema.h:853
ola::web::AnyOfValidator::AnyOfValidator
AnyOfValidator(ValidatorList *validators)
Definition JsonSchema.h:860
ola::web::ArrayValidator::AdditionalItems
Definition JsonSchema.h:664
ola::web::ArrayValidator::Items
Definition JsonSchema.h:635
ola::web::ArrayValidator
The validator for JsonArray.
Definition JsonSchema.h:629
ola::web::ArrayValidator::ArrayValidator
ArrayValidator(Items *items, AdditionalItems *additional_items, const Options &options)
Validate all elements of the array against the given schema.
Definition JsonSchema.cpp:464
ola::web::BaseValidator::SetDescription
void SetDescription(const std::string &title)
Set the description.
Definition JsonSchema.cpp:95
ola::web::BaseValidator::SetDefaultValue
void SetDefaultValue(const JsonValue *value)
Set the default value for this validator.
Definition JsonSchema.cpp:99
ola::web::BaseValidator::SetSchema
void SetSchema(const std::string &schema)
Set the schema.
Definition JsonSchema.cpp:83
ola::web::BaseValidator::SetTitle
void SetTitle(const std::string &title)
Set the title.
Definition JsonSchema.cpp:91
ola::web::BaseValidator::GetSchema
virtual JsonObject * GetSchema() const
Returns the Schema as a JsonObject.
Definition JsonSchema.cpp:49
ola::web::BaseValidator::IsValid
virtual bool IsValid() const
Check if the value was valid according to this validator.
Definition JsonSchema.h:131
ola::web::BaseValidator::SetId
void SetId(const std::string &id)
Set the id.
Definition JsonSchema.cpp:87
ola::web::BaseValidator::AddEnumValue
void AddEnumValue(const JsonValue *value)
Add a enum value to the list of allowed values.
Definition JsonSchema.cpp:107
ola::web::BaseValidator::GetDefaultValue
const JsonValue * GetDefaultValue() const
Return the default value.
Definition JsonSchema.cpp:103
ola::web::ConjunctionValidator::ConjunctionValidator
ConjunctionValidator(const std::string &keyword, ValidatorList *validators)
Definition JsonSchema.cpp:678
ola::web::IntegerValidator::AddConstraint
void AddConstraint(NumberConstraint *constraint)
Add a constraint to this validator.
Definition JsonSchema.cpp:243
ola::web::JsonArray
An array of JSON values. Arrays in JSON can contain values of different types.
Definition Json.h:1043
ola::web::JsonBool
A Bool value.
Definition Json.h:774
ola::web::JsonDouble
A double value.
Definition Json.h:654
ola::web::JsonInt64
A signed 64bit int value.
Definition Json.h:581
ola::web::JsonInt
A signed 32bit int value.
Definition Json.h:447
ola::web::JsonNull
The null value.
Definition Json.h:818
ola::web::JsonNumber
JsonNumber is the base class for various integer / number classes.
Definition Json.h:325
ola::web::JsonNumber::MultipleOf
virtual bool MultipleOf(const JsonNumber &other) const =0
Checks if the remainder if non-0;.
ola::web::JsonObject
A JSON object. JSON Objects are key : value mappings, similar to dictionaries in Python.
Definition Json.h:899
ola::web::JsonObject::AddValue
void AddValue(const std::string &key, JsonValue *value)
Set the key to the supplied JsonValue.
Definition Json.cpp:667
ola::web::JsonObject::Add
void Add(const std::string &key, const std::string &value)
Add a key to string mapping.
Definition Json.cpp:607
ola::web::JsonObjectPropertyVisitor
A class used to visit Json values within a JsonObject.
Definition Json.h:1226
ola::web::JsonRawValue
A raw value, useful if you want to cheat.
Definition Json.h:850
ola::web::JsonSchema::AsJson
const JsonObject * AsJson() const
Return the schema as Json.
Definition JsonSchema.cpp:800
ola::web::JsonSchema::FromString
static JsonSchema * FromString(const std::string &schema_string, std::string *error)
Parse a string and return a new schema.
Definition JsonSchema.cpp:809
ola::web::JsonSchema::IsValid
bool IsValid(const JsonValue &value)
Validate a JsonValue against this schema.
Definition JsonSchema.cpp:795
ola::web::JsonString
A string value.
Definition Json.h:279
ola::web::JsonUInt64
An unsigned 64bit int value.
Definition Json.h:513
ola::web::JsonUInt
An unsigned 32bit int value.
Definition Json.h:380
ola::web::JsonValueConstVisitorInterface
The const interface for the JsonValueVisitor class.
Definition Json.h:99
ola::web::JsonValue
The base class for JSON values.
Definition Json.h:119
ola::web::MaximumConstraint::MaximumConstraint
MaximumConstraint(const JsonNumber *limit, bool is_exclusive)
Create a new MaximumConstraint.
Definition JsonSchema.h:397
ola::web::MaximumConstraint::MaximumConstraint
MaximumConstraint(const JsonNumber *limit)
Create a new MaximumConstraint.
Definition JsonSchema.h:407
ola::web::MinimumConstraint::MinimumConstraint
MinimumConstraint(const JsonNumber *limit)
Create a new MaximumConstraint.
Definition JsonSchema.h:450
ola::web::MinimumConstraint::MinimumConstraint
MinimumConstraint(const JsonNumber *limit, bool is_exclusive)
Create a new MaximumConstraint.
Definition JsonSchema.h:440
ola::web::NumberConstraint
The base class for constraints that can be applies to the Json number type.
Definition JsonSchema.h:357
ola::web::ObjectValidator::VisitProperty
void VisitProperty(const std::string &property, const JsonValue &value)
Visit the value at the given property.
Definition JsonSchema.cpp:381
ola::web::ObjectValidator::SetAdditionalValidator
void SetAdditionalValidator(ValidatorInterface *validator)
Add the validator for additionalProperties.
Definition JsonSchema.cpp:306
ola::web::ObjectValidator::AddSchemaDependency
void AddSchemaDependency(const std::string &property, ValidatorInterface *validator)
Add a schema dependency.
Definition JsonSchema.cpp:310
ola::web::ObjectValidator::AddValidator
void AddValidator(const std::string &property, ValidatorInterface *validator)
Add a validator for a property.
Definition JsonSchema.cpp:301
ola::web::ObjectValidator::AddPropertyDependency
void AddPropertyDependency(const std::string &property, const std::set< std::string > &properties)
Add a property dependency.
Definition JsonSchema.cpp:315
ola::web::OneOfValidator
A validator which ensures at only one of the child validators pass (oneOf).
Definition JsonSchema.h:876
ola::web::OneOfValidator::OneOfValidator
OneOfValidator(ValidatorList *validators)
Definition JsonSchema.h:883
ola::web::ReferenceValidator::ReferenceValidator
ReferenceValidator(const SchemaDefinitions *definitions, const std::string &schema)
Definition JsonSchema.cpp:126
ola::web::ReferenceValidator::GetDefaultValue
const JsonValue * GetDefaultValue() const
Return the default value for this validator.
Definition JsonSchema.cpp:192
ola::web::ReferenceValidator::IsValid
bool IsValid() const
Check if the value was valid according to this validator.
Definition JsonSchema.cpp:133
ola::web::ReferenceValidator::GetSchema
JsonObject * GetSchema() const
Returns the Schema as a JsonObject.
Definition JsonSchema.cpp:181
ola::web::ReferenceValidator::SetSchema
void SetSchema(const std::string &schema)
Set the $schema property for this validator.
Definition JsonSchema.cpp:187
ola::web::ReferenceValidator::SetDescription
void SetDescription(const std::string &title)
Set the description property for this validator.
Definition JsonSchema.cpp:190
ola::web::ReferenceValidator::SetTitle
void SetTitle(const std::string &title)
Set the title property for this validator.
Definition JsonSchema.cpp:189
ola::web::ReferenceValidator::SetId
void SetId(const std::string &id)
Set the id property for this validator.
Definition JsonSchema.cpp:188
ola::web::ReferenceValidator::SetDefaultValue
void SetDefaultValue(const JsonValue *value)
Set the default value for this validator.
Definition JsonSchema.cpp:191
ola::web::SchemaDefinitions
Definition JsonSchema.h:960
ola::web::StringValidator
The validator for JsonString.
Definition JsonSchema.h:294
ola::web::ValidatorInterface
The interface Json Schema Validators.
Definition JsonSchema.h:56
ola::web::ValidatorInterface::GetSchema
virtual JsonObject * GetSchema() const =0
Returns the Schema as a JsonObject.
ola::web::ValidatorInterface::SetDescription
virtual void SetDescription(const std::string &title)=0
Set the description property for this validator.
ola::web::ValidatorInterface::ValidatorList
std::vector< ValidatorInterface * > ValidatorList
a list of Validators.
Definition JsonSchema.h:61
ola::web::ValidatorInterface::SetSchema
virtual void SetSchema(const std::string &schema)=0
Set the $schema property for this validator.
ola::web::ValidatorInterface::SetDefaultValue
virtual void SetDefaultValue(const JsonValue *value)=0
Set the default value for this validator.
ola::web::ValidatorInterface::GetDefaultValue
virtual const JsonValue * GetDefaultValue() const =0
Return the default value for this validator.
ola::web::ValidatorInterface::IsValid
virtual bool IsValid() const =0
Check if the value was valid according to this validator.
ola::web::ValidatorInterface::SetTitle
virtual void SetTitle(const std::string &title)=0
Set the title property for this validator.
ola::web::ValidatorInterface::SetId
virtual void SetId(const std::string &id)=0
Set the id property for this validator.
ola::web::WildcardValidator::IsValid
bool IsValid() const
Check if the value was valid according to this validator.
Definition JsonSchema.h:243
ola::STLDeleteElements
void STLDeleteElements(T *sequence)
Delete the elements of a Sequence.
Definition STLUtils.h:99
ola::web
Classes to deal with web services.
Definition Json.cpp:29
ola::web::JsonType
JsonType
The type of JSON data element.
Definition JsonTypes.h:44
ola::web::JSON_NUMBER
@ JSON_NUMBER
Definition JsonTypes.h:49
ola::web::JSON_STRING
@ JSON_STRING
Definition JsonTypes.h:51
ola::web::JSON_BOOLEAN
@ JSON_BOOLEAN
Definition JsonTypes.h:46
ola::web::JSON_NULL
@ JSON_NULL
Definition JsonTypes.h:48
ola::web::JSON_INTEGER
@ JSON_INTEGER
Definition JsonTypes.h:47
ola::web::JSON_UNDEFINED
@ JSON_UNDEFINED
Definition JsonTypes.h:52
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::web::ArrayValidator::Options
Definition JsonSchema.h:687
ola::web::ObjectValidator::Options
Definition JsonSchema.h:533
ola::web::StringValidator::Options
Definition JsonSchema.h:296