Skip to content

Allow partial filters on embedded resources in OpenAPI schema generation #310

@nallwhy

Description

@nallwhy

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.

%{
  "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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions