From e53e04c00ae81b13b3f74a2806e798725714ff7a Mon Sep 17 00:00:00 2001 From: Krishnaprasad MG Date: Tue, 6 Jun 2017 19:51:31 +0200 Subject: [PATCH] Added property name in draft-3 required error (#432) Backport modifications: * Change error syntax to use the old pre-6.0.0 API --- src/JsonSchema/Constraints/UndefinedConstraint.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index a86afcac..c0606ff9 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -142,7 +142,13 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer } elseif (isset($schema->required) && !is_array($schema->required)) { // Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true} if ($schema->required && $value instanceof self) { - $this->addError($path, 'Is missing and it is required', 'required'); + $propertyPaths = $path->getPropertyPaths(); + $propertyName = end($propertyPaths); + $this->addError( + $path, + 'The property ' . $propertyName . ' is required', + 'required' + ); } } }