-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Fix validation rule accepted #438
Fix validation rule accepted #438
Conversation
@@ -188,6 +188,12 @@ protected function parseRule($rule, array &$parameterData, bool $independentOnly | |||
case 'required': | |||
$parameterData['required'] = true; | |||
break; | |||
case 'accepted': | |||
$parameterData['required'] = true; | |||
$parameterData['type'] = 'boolean'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but doesn't the documentation say it can be "yes" or 1? I don't think we can conclusively assign a boolean
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right if we think in terms of strict typing. I wanted it to be consistent with the boolean
validation rule, which can be true, false as well as 1, 0, "1" and "0" (but I see there's no "yes" and "no" option). It is still considered a boolean
type in Scribe.
If we leave the type empty, it will default to string
type, which I don't think makes much sense either, and from what I can see, displaying multiple available types would be pretty hacky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. And it's an API after all. Not very likely we'll have a "yes" sent in.
@shalvah I'm sorry, can you provide guidance on issues that popped up here? I noticed that lint errors appeared before I started implementing thi PR. I can fix the issue about |
Just ignore any lint errors that aren't from your code. |
@Hiszpek can you fix the tests? |
@shalvah The reason the tests on 7.4 fail is because it contains Laravel 6.20, but the Sorry for leaving this hanging for a while. |
Seems like there's already an example for what to do in that file: scribe/tests/Unit/ValidationRuleParsingTest.php Lines 323 to 329 in 04ac914
|
6260a1f
to
5e751b0
Compare
When using
accepted
oraccepted_if
validation rules on a field, the generated body parameters documentation hints that the value is an optional string. This is not true, as you can see in the Laravel Validation documentation: https://laravel.com/docs/9.x/validation#rule-acceptedThis PR aims to change the type, description and requirement of fields with those rules.
Documentation and example request generated before the changes:
![image](https://user-images.githubusercontent.com/74194396/153875649-95c4768c-8a5f-4071-91d0-01c34346b721.png)
![image](https://user-images.githubusercontent.com/74194396/153876121-6fc509e1-343e-4329-bbd6-5492e9ecbb77.png)
Documentation and example request generated after the changes:
![image](https://user-images.githubusercontent.com/74194396/153875818-634d3991-5354-46f0-9b14-bd354dca8da5.png)
![image](https://user-images.githubusercontent.com/74194396/153876629-27daff89-0384-48cf-900b-6b1acc55a20f.png)