-
-
Notifications
You must be signed in to change notification settings - Fork 917
tests: test parameters type detection #7240
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
base: 4.1
Are you sure you want to change the base?
tests: test parameters type detection #7240
Conversation
c524727
to
3f4932a
Compare
3f4932a
to
4f58677
Compare
...Validator/Metadata/Resource/Factory/ParameterValidationResourceMetadataCollectionFactory.php
Outdated
Show resolved
Hide resolved
|
||
// Allow null in case of optional parameter | ||
if (isset($schema['type']) && 'boolean' === $schema['type']) { | ||
$assertions[] = new Expression(expression: 'value in [null, 0, 1, "0", "1", false, true, "false", "true"]'); |
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.
I'm not a huge fan of using an expression, I'd prefer to use Assert\IsTrue
or Assert\IsFalse
or why not even Assert\Type
. This leads to the same issue as above that is that parameters are always strings. Suggestion: let's add a new castToNativeType
option on parameters, if its true
we can cast the string to the native type inside the ApiPlatform\State\Provider\ParameterProvider
(there's a function in type info for that IIRC). Then, if castToNativeType
is true we can safely add an Assert\Type
constraint.
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.
@soyuka does this commit suit your proposition?
b34e067
to
f7a4639
Compare
f7a4639
to
f1c3bbb
Compare
No description provided.