ash-project / ash_json_api

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

open_api is not correctly updating when you add default fields into a route #111

Closed thejohnnybot closed 5 months ago

thejohnnybot commented 8 months ago

To Reproduce

# :current_balance calculated field
routes do
  index :read, default_fields: [:currency, :identifier, :current_balance]
end

Expected behavior fields section should be updated to include new fields

** Runtime

zachdaniel commented 8 months ago

So, I've made some changes in main that should address this better. What you will probably want to do is first begin by using the new top level default fields option

json_api do
  default_fields [:currency, :identifier, :current_balance]
end

As that will alter the root object type definition for the resource. With the changes I've made, if you use the route-specific default_fields option, we no longer make a reference to the root type, as the route produces a type different from the default type.

If you can, please try main and let me know how it goes.

thejohnnybot commented 8 months ago

Hi @zachdaniel I tested the changes and updated the code to follow your approach, it did not correct the issue and now it also modified the open_api filters so now it thinks strings are object searches.

zachdaniel commented 8 months ago

Well, the strings are object searches. You'd do filter[name][eq]=value. Although I guess it could be a string or an object, as filter[name]=value

zachdaniel commented 8 months ago

It must have changed something right? Did you move the default_fields to the resource level?

thejohnnybot commented 8 months ago

@zachdaniel yes I moved the fields to the resource level but the swaggerui did not show the updated changes. Also when I was mentioning the other thing. the swaggerui did correctly pick up the string attribute but now it wont let me run a test with the same payload on the ui saying I am doing a invalid filter

zachdaniel commented 8 months ago

What I changed about it is that it should show all fields, with a comment in the description about the fields that are included by default. Since technically every key can be omitted with the fields option. Are you seeing the extra fields as not showing up?

zachdaniel commented 8 months ago

Okay, the filter thing should be fixed in main now.