New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation #405
Validation #405
Conversation
bea2f6b
to
06c8585
Compare
Last of the points — it'll be quite easy with validation groups. Others — I'd suggest to simply create something like tagged adapters loop with |
I don't see the point of using validation groups here ? Since we want to validate all the model everytime. What this kind of complexity (tagged adapters, which won't really work like that since Jane is something that should work out of Symfony scope) will bring to Jane ? instead of this validator file that contains all the constraints ? |
f2286b8
to
5e8dd24
Compare
@joelwurtz gave me a quick review about how he thinks the validation should be done and gave me a really good example of how he see the generated validator: namespace Jane\JsonSchema\Tests\Expected\Validator;
class ModelValidator implements Jane\JsonSchema\Tests\Expected\Validator\ValidatorInterface
{
public function __construct(Symfony\Component\Validator\Validation $validator = null)
{
$this->validator = $validator ?? \Symfony\Component\Validator\Validation::createValidator();
}
public function validate($data): ConstraintViolationListInterface
{
return $this->validator->validate($data, self::getConstraint());
}
public function static getConstraint(): ConstraintInterface
{
// add some cache here ~
return new \Symfony\Component\Validator\Constraints\Collection(array('enumString' => new \Symfony\Component\Validator\Constraints\Required(array(new \Symfony\Component\Validator\Constraints\Choice(array('choices' => array('foo', 'bar', 'baz'), 'message' => '"{{ value }}" is not part of the set of possible choices for this field: "{{ choices }}".')))), 'enumArrayString' => new \Symfony\Component\Validator\Constraints\Required(array(new \Symfony\Component\Validator\Constraints\Choice(array('choices' => array('foo', 'bar', 'baz'), 'message' => '"{{ value }}" is not part of the set of possible choices for this field: "{{ choices }}".')))), 'enumNoType' => new \Symfony\Component\Validator\Constraints\Required(array(new \Symfony\Component\Validator\Constraints\Choice(array('choices' => array('foo', 'bar', 'baz'), 'message' => '"{{ value }}" is not part of the set of possible choices for this field: "{{ choices }}".'))))));
}
} And was telling me to avoid using exception to get the violation list, he would more see the client returning violations directly when needed (this meant that I should move validation from Normalizers to the Client) |
72b13a9
to
200cd7f
Compare
Hi! What is the status of this issue? |
Actually I did not plan to work on this topic anytime soon since I'm more focusing on v7 and AutoMapper features. Feel free to take over, I made a very detailed todo list in the PR description to what's missing but the big part that is missing is implementing each spec functionality one by one, the validation model is already working. |
Ok, thanks, I'll do some tests with the PR. |
6ce044f
to
ade8284
Compare
e588e2e
to
f5fb063
Compare
And it's done and open for reviews ! @Gounlaf maybe you could take a try there ? |
With pleasure. Will do tonight or tomorrow 😉 |
@Korbeil could you update options and split it in two? As a user, I may want to validate my data before making call to the API I consume, but I don't want to validate that API is sending me "valid" data. So it would be a double options; one for normalization, another one for de-normalization |
5c57325
to
690103c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some wording suggestions in the documentation
src/Component/JsonSchema/Guesser/Validator/Format/IriValidator.php
Outdated
Show resolved
Hide resolved
src/Component/JsonSchema/Guesser/Validator/Format/UriValidator.php
Outdated
Show resolved
Hide resolved
90f8292
to
d602653
Compare
d602653
to
eef17bb
Compare
Fixes #10 (one of the first tickets on this repository !)
Fixes #451
This PR will bring Validation specification thanks to Symfony Validator, this will allow Jane to validate data before normalization or denormalization.
If some validation error is found, Jane will trigger a
ValidationException
(found in the Runtime directory of your Jane generated files with your choosed namespace) containing a violation list.Steps: