Wrong documentation generated for SearchFilter with date properties and exact mode #5161
Replies: 5 comments
-
Do not use the If it worked for you, you were just lucky. 🙈 |
Beta Was this translation helpful? Give feedback.
-
I think the bug label still applies though because the default behaviour in DocumentationNormalizer is not correct. It implies that anything not in Type::$builtinTypes is a string, ignoring the collection part, and at the very least should be string[]. Anyhow, the documentation makes no mention at all about supported use cases for search filter, nor it being designed for strings and/or numbers only. For what types is it designed, then? One could guess strings only going by the name, but then what's exactly doing when you search for a number then? On a more practical side of things, having exact filter around is really useful, because no other built-in filter allows you to filter exactly for one value, or a collection of values. |
Beta Was this translation helpful? Give feedback.
-
You should use |
Beta Was this translation helpful? Give feedback.
-
And you're right. It seems |
Beta Was this translation helpful? Give feedback.
-
To me SearchFilter uses LIKE in sql. Date lookup is much more complicated and is definitely not an officialy supported use case for the SearchFilter. Should we add something in the documentation for this? Your proposed change looks correct, may you propose this patch in a pull request? |
Beta Was this translation helpful? Give feedback.
-
API Platform version(s) affected: 2.5.3
Description
When using SearchFilter on date properties and exact mode, the generated documentation is incorrect. It used to generated a pair of properties, one simple string filter (ie:
date_prop: string
) and one string array filter (ie:date_prop[]: string[]
). Now both are simple strings, even when the second one is nameddate_prop[]
.How to reproduce
Possible Solution
The problems lies in DocumentationNormalizer. When it detects a type that's not in Type::$builtinTypes it defaults to $type = ['string'], irregardless of it being a collection or not. Simple solution would be to return another default when encountering a collection, for example replacing:
$type = \in_array($data['type'], Type::$builtinTypes, true) ? $this->jsonSchemaTypeFactory->getType(new Type($data['type'], false, null, $data['is_collection'] ?? false)) : ['type' => 'string'];
with
$type = \in_array($data['type'], Type::$builtinTypes, true) ? $this->jsonSchemaTypeFactory->getType(new Type($data['type'], false, null, $data['is_collection'] ?? false)) : $this->jsonSchemaTypeFactory->getType(new Type('string', false, null, $data['is_collection'] ?? false));
Additional Context
Beta Was this translation helpful? Give feedback.
All reactions