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

SortFilter and DateFilter are broken on Swagger UI site #6921

Open
ryanhowdy opened this issue Nov 1, 2024 · 4 comments
Open

SortFilter and DateFilter are broken on Swagger UI site #6921

ryanhowdy opened this issue Nov 1, 2024 · 4 comments

Comments

@ryanhowdy
Copy link

API Platform version(s) affected: 4.0.6

Description
I'm using Laravel with the IsApiResource Trait for my example.

OrderFilter
new QueryParameter(key: 'sort[:property]', filter: OrderFilter::class) will not work because on the swagger ui site you do not get the option to set which property you are sorting by, just an option to set 'asc' or 'desc'.

DateFilter
new QueryParameter(key: 'created', filter: DateFilter::class, property: 'created_at') does not work on the swagger ui site because all you get is a box to enter the date value. And whatever you put in there just gets turned into KEY=INPUT.

So if I enter [lte]=2024-07-10 it gets turned into created=[lte]=2024-07-10 when what I really need is create[lte]=2024-07-10.

How to reproduce

  1. Create a new laravel project with at least one table with a date.
  2. Add the following code to the table's model
         return [    
             new ApiResource(
                 operations: [
                     new Get(),
                     new GetCollection(),
                 ],
             ),
             new QueryParameter(key: 'created', filter: DateFilter::class, property: 'created_at'),
         ];
  1. Go to the swagger ui site and try and search for created records before a date.
  2. Notice the actual api call that is run is malformed.
@jonericksonbkjg
Copy link

@ryanhowdy have you found a cure for this? Suffering all sorts of issues with this when running with Laravel.

@ryanhowdy
Copy link
Author

No, i don't think the swagger specs allow for these type of complicated params.

@soyuka
Copy link
Member

soyuka commented Jan 17, 2025

They do allow this:

public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
{
$in = $parameter instanceof QueryParameter ? 'query' : 'header';
$key = $parameter->getKey();
return [
new OpenApiParameter(name: $key.'[after]', in: $in),
new OpenApiParameter(name: $key.'[before]', in: $in),
new OpenApiParameter(name: $key.'[strictly_after]', in: $in),
new OpenApiParameter(name: $key.'[strictly_before]', in: $in),
];
}

There must be a bug I'll investigate, transfering this issue to api-platform/core, thanks for the report!

@jonericksonbkjg please open a new issue.

@soyuka soyuka transferred this issue from api-platform/api-platform Jan 17, 2025
@soyuka
Copy link
Member

soyuka commented Jan 17, 2025

Hi there, I can not reproduce, do you have fields on your model?

Image

https://github.com/api-platform/core/blob/main/src/Laravel/workbench/app/Models/Author.php

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

No branches or pull requests

3 participants