| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #pragma once
- #include <cstdlib>
- #include <map>
- #include <string>
- #include <unordered_set>
- #include <utility>
- #include <vector>
- #include <jvalidate/forward.h>
- namespace jvalidate::constraint {
- /**
- * @brief A constraint on the Object type.
- * Given an argument object, every element that is not subject to a
- * {@see PropertiesConstraint} or {@see PatternPropertiesConstraint} in the
- * same level of the Schema as this constraint is validated against subschema.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.2.3
- */
- struct AdditionalPropertiesConstraint {
- schema::Node const * subschema = nullptr;
- std::unordered_set<std::string> properties;
- std::vector<std::string> patterns;
- };
- /**
- * @brief A constraint on the Object type representing two different
- * constraints:
- * - If a given property is present in the Object, then validate the overall
- * object against the subschema (dependentSchemas).
- * - If a given property is present in the Object, then require that the
- * overall object also contains a list of properties (dependentRequired).
- * Because the explicit separation into different keywords is part of
- * Draft2020-12, the behaviors are merged together for legacy reasons.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.2.2.4
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.5.4
- */
- struct DependenciesConstraint {
- std::map<std::string, schema::Node const *> subschemas;
- std::map<std::string, std::unordered_set<std::string>> required;
- };
- /**
- * @brief A constraint on the Object type with the following characteristic(s):
- * @code{.cpp}
- * arg.size() <= value
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.5.1
- */
- struct MaxPropertiesConstraint {
- size_t value = 0;
- };
- /**
- * @brief A constraint on the Object type with the following characteristic(s):
- * @code{.cpp}
- * arg.size() >= value
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.5.2
- */
- struct MinPropertiesConstraint {
- size_t value = 0;
- };
- /**
- * @brief A constraint on the Object type.
- * Validates properties whose names match a given regex against the subschema.
- * Multiple patterns allowed to match to the same property, meaning that a
- * property can be validated against more than one subschema.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.2.2
- */
- struct PatternPropertiesConstraint {
- std::vector<std::pair<std::string, schema::Node const *>> properties;
- };
- /**
- * @brief A constraint on the Object type.
- * Validates named properties against their matching subschemas. Does not
- * intrinsically require that the property be present in the Object without
- * use of {@see RequiredConstraint}.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.2.1
- */
- struct PropertiesConstraint {
- std::map<std::string, schema::Node const *> properties;
- };
- /**
- * @brief A constraint on the individual keys of an Object type. Since each key
- * is a string, key_schema should be a schema which validates against the
- * String type.
- * @code{.py}
- * for key in arg.keys():
- * key_schema.validate(key)
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.2.4
- */
- struct PropertyNamesConstraint {
- schema::Node const * key_schema = nullptr;
- };
- /**
- * @brief A constraint on the Object type.
- * Validates that the object contains all of the stored properties.
- * @code{.py}
- * all(p in arg for p in properties)
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.5.3
- */
- struct RequiredConstraint {
- std::unordered_set<std::string> properties;
- };
- /**
- * @brief A constraint on the Object type.
- * Given an argument object, every property which is not evaluated by another
- * schema {@see jvalidate::Status::Noop} will be validated against subschema.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-11.3
- */
- struct UnevaluatedPropertiesConstraint {
- schema::Node const * subschema = nullptr;
- };
- }
|