-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feat: Add validation groups on operations #516
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
Feat: Add validation groups on operations #516
Conversation
core/validation.md
Outdated
@@ -167,6 +167,70 @@ Of course, you can use XML or YAML configuration format instead of annotations i | |||
You may also pass in a [group sequence](http://symfony.com/doc/current/validation/sequence_provider.html) in place of | |||
the array of group names. | |||
|
|||
## Using Validation Groups on operations | |||
|
|||
There are [5 types of operations](operations.md) in API Platform and you can have different validation for each. |
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.
validations?
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.
I would reword There are [5 types of operations](operations.md)
. It's not exact: there are 2 builtin collection operations, and 4 item operations (PATCH is JSONAPI specific), but API Platform supports any type and any number of operations.
core/validation.md
Outdated
/** | ||
* @ApiResource( | ||
* collectionOperations={ | ||
* "get"={"method"="GET"}, |
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.
Maybe you can remove the explicit method declaration to be clearer?
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.
ping @dunglas
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.
When declaring the POST method, we have to declare the GET method to access it.
That's why I wanted to put it, because we often need the GET on the collection
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.
No, I'm saying you can do like this:
* collectionOperations={
* "get",
* "post"={"validation_groups"={"Default", "postValidation"}}
* },
core/validation.md
Outdated
|
||
`postValidation` contains the constraints on the name and author (length from 2 to 50) fields only. | ||
|
||
`putValidation` contains the constraints on the author (length from 2 to 70) fields only. |
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.
field
core/validation.md
Outdated
|
||
With this configuration, there are three validation groups: | ||
|
||
`Default` contains the constraints in the current class and all referenced classes that belong to no other group. |
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.
I don't understand the all referenced classes
part. You need a Valid
assert for this kind of behavior, don't you?
core/validation.md
Outdated
@@ -167,6 +167,70 @@ Of course, you can use XML or YAML configuration format instead of annotations i | |||
You may also pass in a [group sequence](http://symfony.com/doc/current/validation/sequence_provider.html) in place of | |||
the array of group names. | |||
|
|||
## Using Validation Groups on operations | |||
|
|||
There are [2 builtin collection operations, and 4 item operations](operations.md) (PATCH is JSONAPI specific), but API Platform supports any type and any number of operations. |
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.
I would reword it like this:
You can have different validation for each [operation](operations.md) related to your resource.
Like this you don't need to duplicate the explanation about the concept of operations in API Platform.
core/validation.md
Outdated
* @ApiResource( | ||
* collectionOperations={ | ||
* "get", | ||
* "post"={"method"="POST", "validation_groups"={"Default", "postValidation"}} |
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.
I think it's working if you remove the method
part but I'm not sure about this.
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.
It is.
core/validation.md
Outdated
* itemOperations={ | ||
* "delete", | ||
* "get", | ||
* "put"={"method"="PUT", "validation_groups"={"Default", "putValidation"}} |
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.
same here, you can remove "method"="PUT"
core/validation.md
Outdated
@@ -167,6 +167,70 @@ Of course, you can use XML or YAML configuration format instead of annotations i | |||
You may also pass in a [group sequence](http://symfony.com/doc/current/validation/sequence_provider.html) in place of | |||
the array of group names. | |||
|
|||
## Using Validation Groups on operations |
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.
Operations
@dunglas @alanpoulain Done |
Thanks @toofff |
No description provided.