ash-project / ash-project/ash_json_api

Allow partial filters on embedded resources in OpenAPI schema generation

Open
#310 1 comment 0 reactions 0 assignees View on GitHub
bug needs review
Dominant language
Elixir
Stars
94
Forks
80
Avg merge
5h 5m
Merged PRs (30d)
4

Description

**Describe the bug**

When generating filter schemas using `AshJsonApi.OpenApi.raw_filter_type/2`, filtering on embedded resources currently requires all attributes of the embedded struct to match. This means it’s not possible to query based on partial conditions (i.e., using `at_path`) for specific fields within the embedded resource.

```elixir
%{
"description" => "Filter results",
"properties" => %{
"bio" => %{
"additionalProperties" => false,
"properties" => %{
"eq" => %{
"additionalProperties" => false,
"properties" => %{
"birth" => %{
"anyOf" => [
%{
"description" => "Field included by default.",
"format" => "date",
"nullable" => true,
"type" => "string"
},
%{"type" => "null"}
]
},
"nationality" => %{
"anyOf" => [
%{
"description" => "Field included by default.",
"nullable" => true,
"type" => "string"
},
%{"type" => "null"}
]
}
},
"type" => "object"
}
}
}
}
}
```

**To Reproduce**

Run `AshJsonApi.OpenApi.raw_filter_type/2` with any resource that has embedded resource.

**Expected behavior**

To allow multiple `at_path` filters on an embedded resource, it seems necessary to pass **a list of filters** to `Ash.Query.filter_input/2`. Therefore, the filter type should be wrapped in an array in the generated JSON schema to properly support this use case.

**Runtime**
- Elixir version: 1.18
- Erlang version: 27
- OS: mac
- Ash version: 3.5.1
- any related extension versions: AshJsonAPI 1.4.22

**Additional context**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.