| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #pragma once
- #include <cstdlib>
- #include <memory>
- #include <set>
- #include <vector>
- #include <jvalidate/forward.h>
- namespace jvalidate::constraint {
- /**
- * @brief A constraint on any JSON document.
- * Validates that the given document is validated by the EVERY one of the
- * child schemas.
- * @code{.py}
- * all(c.validate(arg) for c in children)
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.2.1.1
- */
- struct AllOfConstraint {
- std::vector<SubConstraint> children;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates that the given document is validated by the AT LEAST one of the
- * child schemas.
- * @code{.py}
- * any(c.validate(arg) for c in children)
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.2.1.2
- */
- struct AnyOfConstraint {
- std::vector<SubConstraint> children;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates that the input json is exactly the single stored value.
- * Stored values can be simple scalars (bool, number, string, null), or
- * complicated documents.
- * @code{.py}
- * arg == value
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.3
- */
- struct ConstConstraint {
- std::unique_ptr<adapter::Const const> value;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates that the input json is one of the stored values.
- * Stored values can be simple scalars (bool, number, string, null), or
- * complicated documents.
- * @code{.py}
- * arg in enumeration
- * @endcode
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.2
- */
- struct EnumConstraint {
- std::vector<std::unique_ptr<adapter::Const const>> enumeration;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates that the given document is validated by the EXACTLY one of the
- * child schemas.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.2.1.3
- */
- struct OneOfConstraint {
- std::vector<schema::Node const *> children;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates the document against the if_constraint. If the constraint returns
- * Success or Noop, then the document will be validated against the
- * then_constraint. Otherwise, it will be validated against the else_constraint.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.2.2
- */
- struct ConditionalConstraint {
- schema::Node const * if_constraint = nullptr;
- schema::Node const * then_constraint = nullptr;
- schema::Node const * else_constraint = nullptr;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates that the given document is NOT validated by the child schema.
- * A result of {@see jvalidate::Status::Noop} is kept as a Noop.
- *
- * https://json-schema.org/draft/2020-12/json-schema-core#section-10.2.1.4
- */
- struct NotConstraint {
- SubConstraint child;
- };
- /**
- * @brief A constraint on any JSON document.
- * Validates that the type of the document is one of the given types.
- *
- * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.1
- */
- struct TypeConstraint {
- std::set<adapter::Type> types;
- };
- }
|