-
-
Notifications
You must be signed in to change notification settings - Fork 910
refactor(metadata): type parameters to list<string>|string #7134
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
Conversation
5fe4473
to
1a8366b
Compare
1a8366b
to
0ebb1f0
Compare
if ($value instanceof ParameterNotFound) { | ||
return $value; | ||
} | ||
|
||
$isCollectionType = fn ($t) => $t instanceof CollectionType; | ||
$isCollection = $parameter->getNativeType()?->isSatisfiedBy($isCollectionType) ?? false; | ||
|
||
// type-info 7.2 | ||
if (!$isCollection && $parameter->getNativeType() instanceof UnionType) { | ||
foreach ($parameter->getNativeType()->getTypes() as $t) { | ||
if ($isCollection = $t->isSatisfiedBy($isCollectionType)) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if ($isCollection) { | ||
$value = \is_array($value) ? $value : [$value]; | ||
} elseif ($parameter instanceof HeaderParameter && \is_array($value) && array_is_list($value) && 1 === \count($value)) { | ||
$value = $value[0]; | ||
} | ||
|
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.
Hello 👋
There is a BC break here.
On on resource, we have this (simplified version) :
#[ApiResource(
shortName: 'PublicDraft',
operations: [
new GetCollection(
parameters: new Parameters([
new QueryParameter(
key: 'triggerUrl',
constraints: [new Source()],
),
])
),
],
)]
our request looks like this
curl --request GET \
--url 'https://api.redirection-io.test/app_dev.php/drafts?projectId=d98a60e4-56f4-11ea-8b8d-0242ac150003&triggerUrl=foobar' \
--header 'Authorization: Bearer 4781249f79bfbdfb1f3c11b2cfc88c5e1a434c9c579b19f5315ec5677051'
And in our validator, we use to receive a string, now we receive a array
We have symfony/type-info: 7.2.5 (but we do not reach line 88), because the $parameter->getNativeType is already a collection :
I tried to specify the nativeType, but I got the same result. It looks like it's not used.
nativeType: new BuiltinType(TypeIdentifier::STRING),
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.
Oh, I missed #7157, sorry ! and the last release fixed it. Thanks!
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.
also parameters are experimental :D
Adds a nativeType to parameters, defaults to
list<string>|string
as this is the default with Symfony query parameters parsing and for HTTP Headers. It also fixes the value extraction accordingly and the validation that may have work partially on a value that's extracted as an array.TODO: