Skip to content

Fix the validation of an array of objects#40

Open
DavidePastore wants to merge 9 commits into
masterfrom
add-array-validation-at-first-position
Open

Fix the validation of an array of objects#40
DavidePastore wants to merge 9 commits into
masterfrom
add-array-validation-at-first-position

Conversation

@DavidePastore

@DavidePastore DavidePastore commented Sep 6, 2018

Copy link
Copy Markdown
Owner
  • Update the source code;
  • Create some tests with nested structures or empty array as input
  • Update the documentation
  • Create a test with an array in POST and another parameter in GET

Close #39.

@tamaspanczel

Copy link
Copy Markdown

Doesn't work if you mix post array objects with query params:

POST /someurl?test=1
[1,2,3]

in Validation.php: __invoke $params = $request->getParams(); will be:

Array
(
    [test] => 1
    [0] => 1
    [1] => 2
    [2] => 3
)

@DavidePastore

DavidePastore commented Oct 6, 2018

Copy link
Copy Markdown
Owner Author

Hi @tamaspanczel. Is it related to this PR? If yes, in which way? If not, please create an issue for this problem.

@tamaspanczel

Copy link
Copy Markdown

Ok, I'll create an issue for this, thx.

@DavidePastore DavidePastore force-pushed the add-array-validation-at-first-position branch from 26f08f3 to 6904fc7 Compare January 3, 2019 15:01
@craig-cogdill

Copy link
Copy Markdown

Hey @DavidePastore, this doesn't appear to be working as I expected. I think I led you astray with the use of v::each(). I've taken a closer look at the documentation for each() (https://respect-validation.readthedocs.io/en/1.1/rules/Each/) and it seems like the validator iterates over only key:value pairs of an array, not any objects within an array.

Per my feature request (#39), I am trying to validate key:value pairs within an array of objects, so I'm not sure this PR would fix that.

However, it seems like a good enhancement regardless since it allows generic validation of array input such as

[
   "key1": "value1",
   "key2": "value2"
]

I don't have any routes with this format, so I don't think I can verify this PR for you currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validating an array of objects

3 participants