#pragma once #include #include #include #include #include #include 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; std::unordered_set properties; std::vector 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 subschemas; std::map> 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 { int64_t value; }; /** * @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 { int64_t value; }; /** * @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> 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 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; }; /** * @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 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; }; }