ash-project / ash_json_api

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

Generated OpenAPI spec does not list all possible values for a sort field #182

Closed sevenseacat closed 1 month ago

sevenseacat commented 1 month ago

Describe the bug

I've built a web UI for an app that allows sorting a resource using the query: [sort_input: "-inserted_at"] syntax for a read action. sort_input accepts any public field, including aggregates and calculations, and this works great.

I've exposed the same action in an API generated with AshJsonApi and the list of possible options it says it accepts is shorter - it lists all public attributes, but not aggregates or calculations.

          {
            "description": "Sort order to apply to the results",
            "explode": false,
            "in": "query",
            "name": "sort",
            "required": false,
            "schema": {
              "items": {
                "enum": [
                  "id",
                  "-id",
                  "name",
                  "-name",
                  "biography",
                  "-biography",
                  "previous_names",
                  "-previous_names",
                  "inserted_at",
                  "-inserted_at",
                  "updated_at",
                  "-updated_at"
                ],
                "type": "string"
              },
              "type": "array"
            },
            "style": "form"
          },

Other values still work if provided to the API, but this list of options is used in things like Swagger UI documentation to populate a select box, so other valid values couldn't be entered.

Plus, the documentation should really cover all possible values if it says it does!

On a somewhat-unrelated note, is it possible to customize this list/the filter list to not allow filtering/sorting by some public attributes? In this example, previous_names is an array, which doesn't make too much sense to filter/sort on. (Attempting to filter on previous_names generates an error when attempted from SwaggerUI, anyhow.)

Expected behavior

The enum in the generated OpenAPI documentation should list all public attributes in ascending/descending forms, including aggregates and calculations.

Runtime

zachdaniel commented 1 month ago

There is not a way to do it at the json_api level, but all fields have a sortable? and filterable? option that can be set to false at the resource level.