Skip to content

Filter spec generator is missing contains operator for string fields #302

@lcmen

Description

@lcmen

Describe the bug

OpenApiSpex specs does not include all available operators for filtering string-based fields. Example:

"artist-filter-name": {
  "additionalProperties": false,
  "properties": {
    "eq": {
      "type": "string"
    },
    "greater_than": {
      "type": "string"
    },
    "greater_than_or_equal": {
      "type": "string"
    },
    "ilike": {
      "type": "string"
    },
    "in": {
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "is_nil": {
      "type": "boolean"
    },
    "less_than": {
      "type": "string"
    },
    "less_than_or_equal": {
      "type": "string"
    },
    "like": {
      "type": "string"
    },
    "not_eq": {
      "type": "string"
    }
  },
  "type": "object"
}

is missing contains operator which is already supported and translates correctly to LIKE %...% SQL clause

To Reproduce

Add a OpenApiSpex to the router:

scope "/api/json" do
  pipe_through [:api]

  forward "/swaggerui",
          OpenApiSpex.Plug.SwaggerUI,
          path: "/api/json/open_api",
          default_model_expand_depth: 4

  forward "/", TunezWeb.AshJsonApiRouter
end

Configure JSON API representation for a resource

json_api do
  default_fields [:id, :name, :biography, :albums_count, :image_url, :latest_album_year]
  includes [:albums]
  type "artist"
end

Expose resource to JSON API endpoint:

json_api do
  routes do
    base_route "/artists", Tunez.Music.Artist do
      index :search
  end
end

Expected behavior

Open API spec should contain all operators for a field.

** Runtime

  • Elixir version: 1.18.2
  • Erlang version: 15.2.1
  • Ash: 3.4.68
  • Ash JSON API: 1.4.20
  • Ash Postgres: 2.5.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions