|
@@ -101,11 +101,14 @@ private:
|
|
|
std::map<detail::Reference, schema::Node const *> alias_cache_;
|
|
std::map<detail::Reference, schema::Node const *> alias_cache_;
|
|
|
|
|
|
|
|
public:
|
|
public:
|
|
|
- explicit Schema(Adapter auto const & json) : Schema(json, schema_version(json)) {}
|
|
|
|
|
|
|
+ template <Adapter A>
|
|
|
|
|
+ explicit Schema(A const & json, ConstraintFactory<A> const & factory = {})
|
|
|
|
|
+ : Schema(json, schema_version(json), factory) {}
|
|
|
|
|
|
|
|
template <Adapter A>
|
|
template <Adapter A>
|
|
|
- Schema(A const & json, schema::Version version)
|
|
|
|
|
- : schema::Node(ParserContext<A>{.root = *this, .schema = json, .version = version}) {}
|
|
|
|
|
|
|
+ Schema(A const & json, schema::Version version, ConstraintFactory<A> const & factory = {})
|
|
|
|
|
+ : schema::Node(ParserContext<A>{
|
|
|
|
|
+ .root = *this, .schema = json, .version = version, .factory = factory}) {}
|
|
|
|
|
|
|
|
template <typename JSON, typename... Args>
|
|
template <typename JSON, typename... Args>
|
|
|
explicit Schema(JSON const & json, Args &&... args)
|
|
explicit Schema(JSON const & json, Args &&... args)
|
|
@@ -220,12 +223,10 @@ template <Adapter A> Node::Node(ParserContext<A> context) {
|
|
|
description_ = schema["description"].as_string();
|
|
description_ = schema["description"].as_string();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // TODO(samjaffe): Pass this around instead
|
|
|
|
|
- ConstraintFactory<A> factory;
|
|
|
|
|
for (auto [key, subschema] : schema) {
|
|
for (auto [key, subschema] : schema) {
|
|
|
// Using a constraint store allows overriding certain rules, or the creation
|
|
// Using a constraint store allows overriding certain rules, or the creation
|
|
|
// of user-defined extention vocabularies.
|
|
// of user-defined extention vocabularies.
|
|
|
- if (auto make_constraint = factory(key, context.version)) {
|
|
|
|
|
|
|
+ if (auto make_constraint = context.factory(key, context.version)) {
|
|
|
EXPECT_M(not has_reference || context.version >= Version::Draft2019_09,
|
|
EXPECT_M(not has_reference || context.version >= Version::Draft2019_09,
|
|
|
"Cannot directly extend $ref schemas before Draft2019-09");
|
|
"Cannot directly extend $ref schemas before Draft2019-09");
|
|
|
// A constraint may return null if it is not applicable - but otherwise
|
|
// A constraint may return null if it is not applicable - but otherwise
|
|
@@ -234,7 +235,7 @@ template <Adapter A> Node::Node(ParserContext<A> context) {
|
|
|
// Therefore, we parse it alongside parsing "maximum", and could return
|
|
// Therefore, we parse it alongside parsing "maximum", and could return
|
|
|
// nullptr when requesting a constraint pointer for "exclusiveMaximum".
|
|
// nullptr when requesting a constraint pointer for "exclusiveMaximum".
|
|
|
if (auto constraint = make_constraint(context.child(subschema, key))) {
|
|
if (auto constraint = make_constraint(context.child(subschema, key))) {
|
|
|
- auto & into = factory.is_post_constraint(key) ? post_constraints_ : constraints_;
|
|
|
|
|
|
|
+ auto & into = context.factory.is_post_constraint(key) ? post_constraints_ : constraints_;
|
|
|
into.emplace(key, std::move(constraint));
|
|
into.emplace(key, std::move(constraint));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|