Skip to content
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

Cannot validate values of type "NULL" automatically #2731

Closed
norkunas opened this issue Apr 13, 2019 · 3 comments
Closed

Cannot validate values of type "NULL" automatically #2731

norkunas opened this issue Apr 13, 2019 · 3 comments
Labels

Comments

@norkunas
Copy link
Contributor

When calling a collection post operation and if forgot to include a body then the api should handle this gracefully and return a 400 error instead of 500.

Currently it tries to validate "null" because controller result is null and symfony validator obviously doesn't like it.

Response from api:

{  
   "@context":"\/contexts\/Error",
   "@type":"hydra:Error",
   "hydra:title":"An error occurred",
   "hydra:description":"Cannot validate values of type \u0022NULL\u0022 automatically. Please provide a constraint."
}

@soyuka
Copy link
Member

soyuka commented Apr 15, 2019

Duplicate: #1282

@teohhanhui
Copy link
Contributor

See #2757

@jsawicki-internetcompany
Copy link

jsawicki-internetcompany commented Dec 10, 2020

I had the same problem, and solved it by disabling the validation with validate=false in the custom operation in the entity.

 *        "my_custom_operation"={
 *              "input"=MyCustomInput::class,
 *              "method"="POST",
 *              "path"="/an_entity/something",
 *              "controller"=MyCustomAction::class,
 *              "validate"=false,
 *              "normalization_context"={
 *                  "groups"={
 *                      "groupA:read",
 *                  }
 *              },
 *              "denormalization_context"={
 *                  "groups"={
 *                      "groupB:update",
 *                  }
 *              },
 *              "validation_groups"={
 *                  "Default",
 *                  "groupB:update",
 *              }
 *          },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants