|
|
@@ -30,6 +30,7 @@ private:
|
|
|
ValidationConfig cfg_;
|
|
|
ExtensionVisitor extension_;
|
|
|
RE regex_;
|
|
|
+ FormatValidator format_{RE::is_regex};
|
|
|
|
|
|
public:
|
|
|
/**
|
|
|
@@ -40,12 +41,61 @@ public:
|
|
|
* @param cfg Any special (runtime) configuration rules being applied to the
|
|
|
* validator.
|
|
|
*/
|
|
|
- Validator(schema::Node const & schema, ExtensionVisitor extension = {},
|
|
|
+ Validator(schema::Node const & schema, ValidationConfig const & cfg = {})
|
|
|
+ : schema_(schema), cfg_(cfg) {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Construct a Validator
|
|
|
+ *
|
|
|
+ * @param schema The root schema being validated against. Must outlive this.
|
|
|
+ *
|
|
|
+ * @param extension An extension visitor for processing user-defined
|
|
|
+ * constraints
|
|
|
+ *
|
|
|
+ * @param cfg Any special (runtime) configuration rules being applied to the
|
|
|
+ * validator.
|
|
|
+ */
|
|
|
+ Validator(schema::Node const & schema, ExtensionVisitor extension,
|
|
|
ValidationConfig const & cfg = {})
|
|
|
: schema_(schema), cfg_(cfg), extension_(extension) {}
|
|
|
|
|
|
- Validator(schema::Node const & schema, ValidationConfig const & cfg)
|
|
|
- : schema_(schema), cfg_(cfg) {}
|
|
|
+ /**
|
|
|
+ * @brief Construct a Validator
|
|
|
+ *
|
|
|
+ * @param schema The root schema being validated against. Must outlive this.
|
|
|
+ *
|
|
|
+ * @param user_defined_formats A map of format-name to string validator for
|
|
|
+ * user-defined format tools.
|
|
|
+ *
|
|
|
+ * @param cfg Any special (runtime) configuration rules being applied to the
|
|
|
+ * validator. Because user_defined_formats is provided by this constructor,
|
|
|
+ * we default to validate_format:=true.
|
|
|
+ */
|
|
|
+ Validator(schema::Node const & schema,
|
|
|
+ FormatValidator::UserDefinedFormats const & user_defined_formats,
|
|
|
+ ValidationConfig const & cfg = {.validate_format = true})
|
|
|
+ : schema_(schema), cfg_(cfg), format_(user_defined_formats, RE::is_regex) {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Construct a Validator
|
|
|
+ *
|
|
|
+ * @param schema The root schema being validated against. Must outlive this.
|
|
|
+ *
|
|
|
+ * @param extension An extension visitor for processing user-defined
|
|
|
+ * constraints
|
|
|
+ *
|
|
|
+ * @param user_defined_formats A map of format-name to string validator for
|
|
|
+ * user-defined format tools.
|
|
|
+ *
|
|
|
+ * @param cfg Any special (runtime) configuration rules being applied to the
|
|
|
+ * validator. Because user_defined_formats is provided by this constructor,
|
|
|
+ * we default to validate_format:=true.
|
|
|
+ */
|
|
|
+ Validator(schema::Node const & schema, ExtensionVisitor extension,
|
|
|
+ FormatValidator::UserDefinedFormats const & user_defined_formats,
|
|
|
+ ValidationConfig const & cfg = {.validate_format = true})
|
|
|
+ : schema_(schema), cfg_(cfg), extension_(extension),
|
|
|
+ format_(user_defined_formats, RE::is_regex) {}
|
|
|
|
|
|
template <typename... Args> Validator(schema::Node &&, Args &&...) = delete;
|
|
|
|
|
|
@@ -69,7 +119,7 @@ public:
|
|
|
"Cannot perform mutations on an immutable JSON Adapter");
|
|
|
detail::OnBlockExit _ = [&result, this]() { post_process(result); };
|
|
|
return static_cast<bool>(
|
|
|
- ValidationVisitor(schema_, cfg_, regex_, extension_, result).validate(json));
|
|
|
+ ValidationVisitor(schema_, cfg_, regex_, format_, extension_, result).validate(json));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -89,7 +139,7 @@ public:
|
|
|
template <MutableAdapter A> bool validate(A const & json, ValidationResult * result = nullptr) {
|
|
|
detail::OnBlockExit _ = [&result, this]() { post_process(result); };
|
|
|
return static_cast<bool>(
|
|
|
- ValidationVisitor(schema_, cfg_, regex_, extension_, result).validate(json));
|
|
|
+ ValidationVisitor(schema_, cfg_, regex_, format_, extension_, result).validate(json));
|
|
|
}
|
|
|
|
|
|
/**
|