| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #pragma once
- #include <cstdlib>
- #include <optional>
- #include <vector>
- #include <jvalidate/forward.h>
- namespace jvalidate::constraint {
- /**
- * @brief A constraint on the Array type.
- * Given an argument array, every element after applies_after_nth is
- * validated against subschema. applies_after_nth is made to be used in
- * conjunction with {@see TupleConstraint} and cannot be manually specified.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.1.2
- */
- struct AdditionalItemsConstraint {
- schema::Node const * subschema = nullptr;
- size_t applies_after_nth = 0;
- };
- /**
- * @brief A constraint on the Array type, that counts the number of elements
- * in the input array that match subschema and compares that number against
- * minimum and maximum. If minimum is unset, then it is equivalent to a minimum
- * of 1. If maximum is unset, then it is equivalent to a maximum of INF. As an
- * optimization, validation can be stopped after minimum matches if maximum is
- * unset.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.1.3
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.4.4
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.4.5
- */
- struct ContainsConstraint {
- schema::Node const * subschema = nullptr;
- std::optional<size_t> minimum = std::nullopt;
- std::optional<size_t> maximum = std::nullopt;
- };
- /**
- * @brief A constraint on the Array type with the following characteristic(s):
- * @code{.cpp}
- * arg.size() <= value
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.4.1
- */
- struct MaxItemsConstraint {
- size_t value = 0;
- };
- /**
- * @brief A constraint on the Array type with the following characteristic(s):
- * @code{.cpp}
- * arg.size() >= value
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.4.2
- */
- struct MinItemsConstraint {
- size_t value = 0;
- };
- /**
- * @brief A constraint on the Array type.
- * Given an argument array, the Nth element of that Array is validated against
- * the Nth element of items.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.3.1.1
- */
- struct TupleConstraint {
- std::vector<schema::Node const *> items;
- };
- /**
- * @brief A constraint on the Array type.
- * Given an argument array, every element 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.2
- */
- struct UnevaluatedItemsConstraint {
- schema::Node const * subschema = nullptr;
- };
- /**
- * @brief A constraint on the Array type that affirms that each element
- * of the array is unique.
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.4.3
- */
- struct UniqueItemsConstraint {};
- }
|