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

Fixed parsing of nested fields in validation rules #749

Merged
merged 1 commit into from
Nov 19, 2023

Conversation

raphaelflash
Copy link
Contributor

Description

If there are nested fields in the request validation rules, the parsing is incorrect.
This PR fixes this, so that it also works when an array is expected, see examples below.

Screenshots

Before the change
Bildschirmfoto 2023-10-16 um 03 12 22

After the change
Bildschirmfoto 2023-10-16 um 03 11 48

Example request class

class ExampleRequest extends FormRequest
{
    public function rules()
    {
        return [
            '*.foo' => 'required|array',
            '*.foo.*' => 'required|array',
            '*.foo.*.bar' => 'required',
        ];
    }

    public function bodyParameters()
    {
        return [
            '*.foo' => [
                'description' => 'This is not shown (intended?).',
            ],
            '*.foo.*' => [
                'description' => 'A nested field.',
            ],
            '*.foo.*.bar' => [
                'description' => 'A double-nested field.',
            ],
        ];
    }
}

Note: The first description (of *.foo is ignored and will not be shown by scribe. I'm not sure if this is intended?

Example request body

Single object example

[
  {
    "foo": [
      {
        "bar": "hello world"
      }
    ]
  }
]

Multi object example

[
  {
    "foo": [
      {
        "bar": "hello world"
      }
    ]
  },
  {
    "foo": [
      {
        "bar": "hallo welt"
      },
      {
        "bar": "hej världen"
      }
    ]
  }
]

Copy link
Contributor

@shalvah shalvah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@shalvah shalvah merged commit 7b5d1b6 into knuckleswtf:master Nov 19, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants