ash-project / ash_json_api

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

filtering by some integer value is not possible #52

Closed peillis closed 3 years ago

peillis commented 3 years ago

Consider for example an url like /device_screens?filter[screen_id]=12, it gives the following error:

{
    "errors": [
        {
            "code": "InvalidQuery",
            "detail": "Expected \"integer\", got \"1\", at [\"filter\", \"screen_id\"].",
            "id": "c4c36828-785f-4317-b662-2371abcf95a6",
            "source": {
                "parameter": "filter[screen_id]"
            },
            "status": 400,
            "title": "Invalid Query"
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}
zachdaniel commented 3 years ago

Ah, yeah that is no good. If you want to try this out and PR it if it resolves the issue, I'd be grateful: https://github.com/ash-project/ash_json_api/blob/master/lib/ash_json_api/json_schema/json_schema.ex#L325

We can change those "type" => "integer"

Something like this:

%{
  "type" => ["integer", "string"],
  "match" => "^[1-9][0-9]*$"
}

And for boolean

%{
  "type" => ["boolean", "string"]
  "match" => "^(true|false)$"
}

THat might not be exactly right, but it is the gist of it.

peillis commented 3 years ago

Yeah, it works. I already did the PR. Thank you!

zachdaniel commented 3 years ago

Awesome, thanks for the report and for contributing the fix!