Rule::requiredIf treated as required
#934
Replies: 2 comments
-
|
@apasquini95 this is an issue indeed and I consider it a bug! Feel free to create an issue or even submit a PR |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Here's the issue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone and super thanks for this awesome tool :)
I'm quite new to Scramble so maybe I'm missing something, but I noticed that when I write a request body whose rules contains a call to the
Illuminate\Validation\Rule::requiredIf(), the rule is treated as if it was simplyrequired. Here's an example of my request body:The resulting request body specification is represented as follows:
As you can see, the
maybe_requiredfield is marked as required, but is really arequired_ifan "always required"?I gave also a look to the
Dedoc\Scramble\Support\OperationExtensions\RulesExtractor\RulesToParameter::generate()method and I saw that when it is aIlluminate\Validation\Rules\RequiredIfrule object the result of the__toString()method is always'required', even if Laravel produces this string evaluating the given condition:When the condition is not met, Laravel returns an empty string for the
RequiredIfrule, so it shouldn't be really arequiredone. Wouldn't it be simpler to treat aRequiredIfas anullablerule? So the resulting specification would be something like this:Am I missing something maybe or is this intended?
Beta Was this translation helpful? Give feedback.
All reactions