ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
63 stars 43 forks source link

Swagger frontend generates faulty URL when filtering #250

Closed t0rs closed 1 month ago

t0rs commented 1 month ago

When trying to filter on something like this:

{"id": {"eq": "f9d691ee-5f13-4a75-8c13-b917b640119c"}}

Image:

image

It does not generate the correct url which has this included:

?filter[id][eq]=f9d691ee-5f13-4a75-8c13-b917b640119c

But instead generates:

?filter[id]={"eq":"f9d691ee-5f13-4a75-8c13-b917b640119c"}
zachdaniel commented 1 month ago

This is so strange. You're the second person to report this but I can't seem to reproduce this 😢

zachdaniel commented 1 month ago

Okay, I've got it reproduced. Unfortunately I'm not sure if there is much that I can do about it yet.

zachdaniel commented 1 month ago

Relevant issue: https://github.com/OAI/OpenAPI-Specification/issues/1706

zachdaniel commented 1 month ago

@mbuhot Maybe you have some thoughts here? We have a parameter of style :deepObject. It has some fields who's values are :object and some who's value are not (or could be a union of string or object even). The value is being encoded as a JSON string which seems like a very very strange choice. I have a "fix" which is that if the inner things are marked as a :deepObject also (for whatever reason), it just shows a "regular" text box. I could then detect the value of "filter" being a string and query decode it as an object 😂

We should set up a test project we can run locally to try out swagger UI, because I don't have a great way to share an example here currently aside from saying mix igniter.new --with phx.new --install ash,ash_json_api --example --extend json_api and then add an index route.

zachdaniel commented 1 month ago

Okay, @t0rs I've "fixed" this in main in a way I'm not very happy with. Now you type in the query string directly. i.e first_name[eq]=foo&last_name[eq]=bar

zachdaniel commented 1 month ago

I'm not really sure any other way to fix this given the behavior in swagger_ui 🤷