mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-01-19 08:46:42 +01:00
Fix issues in parsing of if/then/else constraints
This commit is contained in:
parent
ef61c8e0de
commit
9b299c9517
@ -714,13 +714,14 @@ private:
|
|||||||
{
|
{
|
||||||
const typename AdapterType::Object::const_iterator ifItr = object.find("if");
|
const typename AdapterType::Object::const_iterator ifItr = object.find("if");
|
||||||
const typename AdapterType::Object::const_iterator thenItr = object.find("then");
|
const typename AdapterType::Object::const_iterator thenItr = object.find("then");
|
||||||
const typename AdapterType::Object::const_iterator elseItr = object.find("end");
|
const typename AdapterType::Object::const_iterator elseItr = object.find("else");
|
||||||
|
|
||||||
if (object.end() != ifItr && object.end() != thenItr) {
|
if (object.end() != ifItr) {
|
||||||
if (version == kDraft7) {
|
if (version == kDraft7) {
|
||||||
rootSchema.addConstraintToSubschema(
|
rootSchema.addConstraintToSubschema(
|
||||||
makeConditionalConstraint(rootSchema, rootNode,
|
makeConditionalConstraint(rootSchema, rootNode,
|
||||||
ifItr->second, thenItr->second,
|
ifItr->second,
|
||||||
|
thenItr == object.end() ? NULL : &thenItr->second,
|
||||||
elseItr == object.end() ? NULL : &elseItr->second,
|
elseItr == object.end() ? NULL : &elseItr->second,
|
||||||
updatedScope, nodePath, fetchDoc, docCache, schemaCache),
|
updatedScope, nodePath, fetchDoc, docCache, schemaCache),
|
||||||
&subschema);
|
&subschema);
|
||||||
@ -731,15 +732,13 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version == kDraft7) {
|
if (version == kDraft7) {
|
||||||
typename AdapterType::Object::const_iterator exclusiveMaximumItr =
|
if ((itr = object.find("exclusiveMaximum")) != object.end()) {
|
||||||
object.find("exclusiveMaximum");
|
|
||||||
if (exclusiveMaximumItr != object.end()) {
|
|
||||||
rootSchema.addConstraintToSubschema(
|
rootSchema.addConstraintToSubschema(
|
||||||
makeMaximumConstraintExclusive(itr->second),
|
makeMaximumConstraintExclusive(itr->second),
|
||||||
&subschema);
|
&subschema);
|
||||||
}
|
}
|
||||||
typename AdapterType::Object::const_iterator maximumItr = object.find("maximum");
|
|
||||||
if (maximumItr != object.end()) {
|
if ((itr = object.find("maximum")) != object.end()) {
|
||||||
rootSchema.addConstraintToSubschema(
|
rootSchema.addConstraintToSubschema(
|
||||||
makeMaximumConstraint<AdapterType>(itr->second, NULL),
|
makeMaximumConstraint<AdapterType>(itr->second, NULL),
|
||||||
&subschema);
|
&subschema);
|
||||||
@ -779,15 +778,13 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version == kDraft7) {
|
if (version == kDraft7) {
|
||||||
typename AdapterType::Object::const_iterator exclusiveMinimumItr =
|
if ((itr = object.find("exclusiveMinimum")) != object.end()) {
|
||||||
object.find("exclusiveMinimum");
|
|
||||||
if (exclusiveMinimumItr != object.end()) {
|
|
||||||
rootSchema.addConstraintToSubschema(
|
rootSchema.addConstraintToSubschema(
|
||||||
makeMinimumConstraintExclusive(itr->second),
|
makeMinimumConstraintExclusive(itr->second),
|
||||||
&subschema);
|
&subschema);
|
||||||
}
|
}
|
||||||
typename AdapterType::Object::const_iterator minimumItr = object.find("minimum");
|
|
||||||
if (minimumItr != object.end()) {
|
if ((itr = object.find("minimum")) != object.end()) {
|
||||||
rootSchema.addConstraintToSubschema(
|
rootSchema.addConstraintToSubschema(
|
||||||
makeMinimumConstraint<AdapterType>(itr->second, NULL),
|
makeMinimumConstraint<AdapterType>(itr->second, NULL),
|
||||||
&subschema);
|
&subschema);
|
||||||
@ -1177,7 +1174,7 @@ private:
|
|||||||
Schema &rootSchema,
|
Schema &rootSchema,
|
||||||
const AdapterType &rootNode,
|
const AdapterType &rootNode,
|
||||||
const AdapterType &ifNode,
|
const AdapterType &ifNode,
|
||||||
const AdapterType &thenNode,
|
const AdapterType *thenNode,
|
||||||
const AdapterType *elseNode,
|
const AdapterType *elseNode,
|
||||||
const opt::optional<std::string> currentScope,
|
const opt::optional<std::string> currentScope,
|
||||||
const std::string &nodePath,
|
const std::string &nodePath,
|
||||||
@ -1193,10 +1190,12 @@ private:
|
|||||||
schemaCache);
|
schemaCache);
|
||||||
constraint.setIfSubschema(ifSubschema);
|
constraint.setIfSubschema(ifSubschema);
|
||||||
|
|
||||||
const Subschema *thenSubschema = makeOrReuseSchema<AdapterType>(
|
if (thenNode) {
|
||||||
rootSchema, rootNode, thenNode, currentScope, nodePath, fetchDoc, NULL, NULL,
|
const Subschema *thenSubschema = makeOrReuseSchema<AdapterType>(
|
||||||
docCache, schemaCache);
|
rootSchema, rootNode, *thenNode, currentScope, nodePath, fetchDoc, NULL, NULL,
|
||||||
constraint.setThenSubschema(thenSubschema);
|
docCache, schemaCache);
|
||||||
|
constraint.setThenSubschema(thenSubschema);
|
||||||
|
}
|
||||||
|
|
||||||
if (elseNode) {
|
if (elseNode) {
|
||||||
const Subschema *elseSubschema = makeOrReuseSchema<AdapterType>(
|
const Subschema *elseSubschema = makeOrReuseSchema<AdapterType>(
|
||||||
|
@ -176,9 +176,13 @@ public:
|
|||||||
ValidationVisitor thenElseValidator(target, context, strictTypes, NULL);
|
ValidationVisitor thenElseValidator(target, context, strictTypes, NULL);
|
||||||
|
|
||||||
if (ifValidator.validateSchema(*constraint.getIfSubschema())) {
|
if (ifValidator.validateSchema(*constraint.getIfSubschema())) {
|
||||||
return thenElseValidator.validateSchema(*constraint.getThenSubschema());
|
const Subschema *thenSubschema = constraint.getThenSubschema();
|
||||||
|
return thenSubschema == nullptr ||
|
||||||
|
thenElseValidator.validateSchema(*thenSubschema);
|
||||||
} else {
|
} else {
|
||||||
return thenElseValidator.validateSchema(*constraint.getElseSubschema());
|
const Subschema *elseSubschema = constraint.getElseSubschema();
|
||||||
|
return elseSubschema == nullptr ||
|
||||||
|
thenElseValidator.validateSchema(*elseSubschema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user