Skip to content

Conversation

@aaa2000
Copy link
Contributor

@aaa2000 aaa2000 commented Dec 22, 2025

Q A
Branch? main for features / current stable version branch for bug fixes
Tickets Closes #5618 , #7465, #4313, #4656, #2838, #3880
License MIT
Doc PR api-platform/docs#...

Add Symfony uuid, Ramsey uuid and Ramsey uuid binary filters.

The PR avoids modifying the search filter to prevent regressions. Furthermore, supporting partial strategies for UUID requires more work. In PostgreSQL, I think we need to cast the UUID to a string in the SQL query.

Possible improvements:

  • filter by IRI
  • Add ODM support
  • Maybe implements \ApiPlatform\Metadata\JsonSchemaFilterInterface

@aaa2000 aaa2000 force-pushed the fix-7465-uuid-filter branch from f80b922 to 7f6964d Compare December 22, 2025 20:04
/**
* @internal
*/
class AbstractUuidFilter extends AbstractFilter implements OpenApiParameterFilterInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not use the AbstractFilter ? It's really not necessary with QueryParameter and this will help skipping all the logic about:

  • property checks
  • value transformation (should be done by our parameter value casting)
  • documentation (use the new interfaces)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, the AbstractUuidFilter no longer uses AbstractFilter

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, also note I'm working on a range filter that can be used with many different types (soyuka@c74675d)

@aaa2000 aaa2000 force-pushed the fix-7465-uuid-filter branch from 7f6964d to f797162 Compare December 29, 2025 15:12
@aaa2000 aaa2000 force-pushed the fix-7465-uuid-filter branch from b7e3778 to 100a022 Compare December 29, 2025 16:24
"api-platform/metadata": "^4.2",
"api-platform/state": "^4.2.4",
"doctrine/orm": "^2.17 || ^3.0"
"doctrine/orm": "^2.17 || ^3.0.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs allowing ArrayParameterType for uuid binary in QueryBuilder doctrine/orm#11287.

So, Uuid binary filter does not work with Doctrine 2.x. Can I skip the tests if Doctrine 2.x is installed and throws an exception in the UuidBianryFilter ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes totally


public function getSchema(Parameter $parameter): array
{
return self::UUID_SCHEMA;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Platform not automatically adds a Symfony Uuid/Ulid constraint, I could create another PR for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaa2000 aaa2000 marked this pull request as ready for review December 30, 2025 12:37
Comment on lines +146 to +152
if (1 === \count($values)) {
$queryBuilder
->andWhere($queryBuilder->expr()->eq($aliasedField, $valueParameter))
->setParameter($valueParameter, $values[0], $this->getDoctrineParameterType());

return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (1 === \count($values)) {
$queryBuilder
->andWhere($queryBuilder->expr()->eq($aliasedField, $valueParameter))
->setParameter($valueParameter, $values[0], $this->getDoctrineParameterType());
return;
}
if (!is_array($values)) {
$queryBuilder
->andWhere($queryBuilder->expr()->eq($aliasedField, $valueParameter))
->setParameter($valueParameter, $values[0], $this->getDoctrineParameterType());
return;
}

Comment on lines +139 to +141
if (!\is_array($values)) {
$values = [$values];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!\is_array($values)) {
$values = [$values];
}

Type casting is done before reaching the filter (see Parameter::castToArray).

return $databaseValues;
}

return $values;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not need this this is done by Doctrine when applying parameters no? If this is really needed could you tell me why? Also you could have a guard clause in the callee and reduce the function complexity.

$this->filterProperty($parameter->getProperty(), $parameter->getValue(), $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
}

protected function filterProperty(string $property, mixed $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this really need to be protected? I'd prefer if it wasn't.


$values = (array) $value;
$associations = [];
if ($this->isPropertyNested($property, $resourceClass)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point I'd like to share the relation filtering logic into other filters, I'm still wondering how we'd make this good enough.


// metadata doesn't have the field, nor an association on the field
if (!$metadata->hasAssociation($field)) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently we log when something goes wrong, maybe add a log information here as the filter looks not valid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants