Core: Why is a propertyName with suffix [] added to search filter when match type is exact?

Created on 30 May 2018  路  5Comments  路  Source: api-platform/core

https://github.com/api-platform/core/blob/e0e639efe4ad0b25f2098b875b6878268bace824/src/Bridge/Doctrine/Orm/Filter/SearchFilter.php#L105

Can anyone explain me why a new property-name with suffix [] is added to the list of property descriptions when the match-type is exact (or when matching an association? Probably i am missing something very obvious here, but i could not deduct this from the existing documentation :1234:

doc question

All 5 comments

I think the documentation about the support for multiple values was lost somewhere along the way... But basically, you could do for example:

/books?author[]=/authors/1&author[]=/authors/2

The effect is equivalent to the SQL IN operator.

Or perhaps it was never properly documented? But it's been around for a long time: https://github.com/api-platform/core/pull/500#issuecomment-212929769 :laughing:

@teohhanhui Thanks for your answer (and sorry for my late reply :yum: ), it does make sense to be able to send in multiple values :+1: .

The swagger definition now contains the two definitions for the same parameter as well, where they are both the same scalar type. If a client is generated this give a pretty weird method signature (i.m.o). Your example would become getBooks(String author1, String author2); i would expect a signature getBooks(String author, List authors), but if multiple values are allowed why not just use the list getBooks(List authors) since they are filtering the same field it would make sense.

  • Shouldn't the generated swagger type for the multi-value scalar be an array?
  • Is it an idea to make the behavior of the generation of the two parameters configurable (like list-only, single-only or both)?

Shouldn't the generated swagger type for the multi-value scalar be an array?

We must fix our Swagger generator to use collectionFormat: multi: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterCollectionFormat

We'll need to document both parameter foo and foo[] because the brackets notation is PHP-specific. Swagger considers both parameters as different ones.

Is it an idea to make the behavior of the generation of the two parameters configurable (like list-only, single-only or both)?

Would be nice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DenisVorobyov picture DenisVorobyov  路  3Comments

Tjeerd picture Tjeerd  路  3Comments

silverbackdan picture silverbackdan  路  3Comments

desmax picture desmax  路  3Comments

rockyweng picture rockyweng  路  3Comments