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

WhenMissing doesn't work in Nested rules. #750

Open
bouledepate opened this issue Oct 17, 2024 · 0 comments
Open

WhenMissing doesn't work in Nested rules. #750

bouledepate opened this issue Oct 17, 2024 · 0 comments
Labels

Comments

@bouledepate
Copy link

Case: Nested parameters should only be validated if the client specifies them in the request.

I have the following declared validation rules.

'regulations' => new Nested(
    rules: [
        'is_one_time' => new BooleanType(
            message: 'Property must be a boolean.',
            skipOnEmpty: new WhenMissing()
        )
    ],
    skipOnEmpty: new WhenMissing()
)

Problem:
When I pass an empty body "regulations", I get a parameter validation error. This should not happen, because the parameter has a condition: "validation must be skipped if the attribute is missing", or WhenMissing.

User cases:

  • I, as a client, make a request with an empty body. As a result, nothing happens, I get success.
{
    "service": "service",
    "amount": 200
}
  • I, as a client, make a request with an empty "regulations". As a result, nothing happens, I get success.
{
    "service": "service",
    "amount": 200,
    "regulations": {}
}

This case does not work. Actually, I get a validation error that "is_one_time must be boolean".

  • I, as a client, make a request with an incorrect value "regulations.is_one_time", I get a validation error.
{
    "service": "service",
    "amount": 200,
    "regulations": {
        "is_one_time": ""
    }
}
  • I, as a client, make a request with a correct value "regulations.is_one_time", I get success.
{
    "service": "service",
    "amount": 200,
    "regulations": {
        "is_one_time": true
    }
}

Selected case is not work.

Additional info

Q A
Version 2.1.0
PHP version 8.3
Operating system Ubuntu 24.04
@vjik vjik added the type:bug Bug label Oct 17, 2024
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