Skip to content
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

RFC: Filters do not respect the configured name converter. #2090

Closed
bendavies opened this issue Jul 11, 2018 · 15 comments
Closed

RFC: Filters do not respect the configured name converter. #2090

bendavies opened this issue Jul 11, 2018 · 15 comments

Comments

@bendavies
Copy link
Contributor

bendavies commented Jul 11, 2018

Hey all,

Here's an issue I discovered today.
If your API has a configured name converter, (let's say CamelCaseToSnakeCaseNameConverter), filtering on fields is unintuitive for the consumer.

Given an ApiResource with a field called createdAt, createdAt will be serialized/deserialized to/from the consumer as created_at.

However, if the consumer wants to then filter on createdAt, they must use ?createdAt..., which is very unintuitive as that is not how the field is represented.

The fix seems simple - make all filters respect the configured name converter.
However, this would be a big BC break, so will need to go in 3.0?

Cheers

@dunglas
Copy link
Member

dunglas commented Jul 11, 2018

I would be in favor of fixing this. It looks totally unexpected on my side. If someone complains... we'll provide a fix like a flag or something like that to restore the buggy behavior. WDYT?

@bendavies
Copy link
Contributor Author

bendavies commented Jul 12, 2018

Cool, while obviously a bug, I didn't expect a fix to be prioritized over the BC break. happy with that!

@soyuka
Copy link
Member

soyuka commented Jul 12, 2018

I didn't expect a fix to be prioritized over the BC break

Most of us are using the default name converter, therefore nothing will change.

@teohhanhui
Copy link
Contributor

Was it ever claimed that the filters would use the name converter? 😛

I don't know if it could be considered a bug if it's a missing feature...

@slebrequier
Copy link

Sorry to have opened a duplicate of this issue.
I, for one, think of it as a bug since the client have to filter from what he knows : the response body.
If the field is called created_at in the response body, then it must be created_at that will filter or sort a list of results.

@alanpoulain alanpoulain added the bug label Oct 6, 2018
@soullivaneuh
Copy link
Contributor

@dunglas To avoid BC break, we could provide a api_platform.name_generator parameter and deprecate the api_platform.path_segment_name_generator one.

@soullivaneuh
Copy link
Contributor

I really need this fix and would like to help making it real, but I don't even know where to start. Could you please give us some clues? Thanks!

@dunglas
Copy link
Member

dunglas commented Nov 5, 2018

To me it’s a bug fix, so don’t bother with BC because the current behavior is not correct (this case has just been forgotten).

A PR would be very appreciated, just target master instead of 2.3 to limit the consequences in case someone was relying on the buggy behavior.

@soullivaneuh
Copy link
Contributor

@dunglas Do you have any clues to give about how to fix it?

@antograssiot
Copy link
Contributor

antograssiot commented Nov 5, 2018

@soullivaneuh Quick and dirty but I guess a start would be master...antograssiot:nameconverter-filter

But it would be a BC break I guess to add an argument in the middle of the constructor, and adding it in the last position, would break definitions like

    app.my_dummy_resource.date_filter:
        parent:    'api_platform.doctrine.orm.date_filter'
        arguments: [ { 'dummyDate': ~, 'relatedDummy.dummyDate': ~, 'embeddedDummy.dummyDate': ~ } ]
        tags:      [ { name: 'api_platform.filter', id: 'my_dummy.date' } ]

as we rely on properties being the last arg

It needs to be tested more deeply and I havent put effort in the SearchFilter yet, if it is considered as BC break.
I'm also unsure of what would be the impact o the admin part etc...
ping @api-platform/core

@soyuka
Copy link
Member

soyuka commented Nov 6, 2018

@antograssiot I think that your changes will do the trick because we use parent in the filter service declaration and we use abstract=true when defining the base services.

To me it’s a bug fix, so don’t bother with BC because the current behavior is not correct (this case has just been forgotten).

To me it's just a missing feature, filter properties are not documented as converted but the same as the property names. I definitely agree that this is inconsistent though.

@soullivaneuh
Copy link
Contributor

@antograssiot on your POC, you use the name converter on each filter getDescription method.

Why not leave this like that and use the name converter only on the documentation normalizer and the filter request extraction?

This will be also better for eventually other supports than Doctrine ORM.

@antograssiot
Copy link
Contributor

I didn't think a lot about the issue @soullivaneuh , I just quickly update with the first (not best) idea I had to see if it would work.. The discalmer was Quick and dirty 😉

@soullivaneuh
Copy link
Contributor

@antograssiot Ha ha right ! 😉

I tried an another approach: #2377

@bendavies
Copy link
Contributor Author

think this is done!

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

No branches or pull requests

8 participants