#pragma once #include #include #include #include #include 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 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 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 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> 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 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 types; }; }