Skip to content

Rule Validator needs recursively convert attributes to an array. #3

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

Closed
lindyhopchris opened this issue Oct 22, 2015 · 4 comments
Closed
Labels

Comments

@lindyhopchris
Copy link
Member

As reported here:
cloudcreativity/json-api#18

This line:
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Validator/Attributes/RulesValidator.php#L149

Needs to recursively change the object to an array before passing into the Laravel validator.

@nickelozz
Copy link

@lindyhopchris hello

I'm using cloudcreativity/laravel-json-api v0.2.1 and I believe I found another bug with the object to array conversion.

For structures that contain an array of objects, these won't get converted into arrays:

// request attributes

"multiple": [
  {
    "val1": "one",
    "val2": "two"
  },
  {
    "val3": "three",
    "val4": "four"
  }
],
"nestedObj": {
  "obj1": {
    "val1": "one",
    "val2": "two"
  },
  "obj2": {
    "val3": "three",
    "val4": "four"
  }
}

// toArray conversion of attributes

"multiple" => [
  {
    "val1": "one",
    "val2": "two"
  },
  {
    "val3": "three",
    "val4": "four"
  }
],
"nestedObj" => [
  "obj1" => [
    "val1" => "one",
    "val2" => "two"
  ],
  "obj2" => [
    "val3" => "three",
    "val4" => "four"
  ]
}

This same behavour happens regardless of the nesting level. Please let me know if I can help any further.

@lindyhopchris
Copy link
Member Author

Hi @nickelozz

Sorry for slow reply - been on holiday. Yes, this is definitely a bug. I'll be able to look at it on Monday when I'm back from holiday.

Cheers,
Chris

@lindyhopchris lindyhopchris reopened this Oct 30, 2015
@lindyhopchris
Copy link
Member Author

@nickelozz

Believe I've now fixed this if you update your cloudcreativity/json-api dependency to v0.3.3

@nickelozz
Copy link

@lindyhopchris I've tested and it works now...thanks so much.

Apparently in the upcoming version (5.2) of Laravel a lot of what I've been doing manually will be "laravelized" thanks to the new "Form Array Validation"... oh well it was a learning experience 😃

In case anyone wants to read about it check here: https://laravel-news.com/2015/11/laravel-5-2-a-look-at-whats-coming/

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

2 participants