Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET routes of a generic action return no id fields even if they are public #263

Closed
diogomrts opened this issue Nov 29, 2024 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@diogomrts
Copy link
Contributor

Description
When setting up a GET route on a generic action, the resource's id is omitted from the response.

To Reproduce
In this example Resource you can see the issue:

defmodule TestRepo.Domain.Generic do
  use Ash.Resource,
    domain: TestRepo.Domain,
    extensions: [AshJsonApi.Resource]

  json_api do
    type("generic")

    routes do
      base "/generic"
      route(:get, "", :create)
    end
  end

  actions do
    action :create, {:array, :struct }do
      constraints items: [instance_of: __MODULE__]

      run fn input, context ->
        {:ok, [%__MODULE__{
          id: 1,
          name: "name"
        }]}
      end
    end
  end

  attributes do
    integer_primary_key(:id, writable?: true, public?: true)
    # attribute(:id, :integer, primary_key?: true, allow_nil?: false, public?: true)
    attribute(:name, :string, public?: true)
  end
end

The response JSON is:

[
  {
    "name": "name"
  }
]

Expected behavior
The expected response should be:

[
  {
    "id": 1,
    "name": "name"
  }
]
@diogomrts diogomrts added bug Something isn't working needs review labels Nov 29, 2024
@zachdaniel
Copy link
Contributor

Took me a while to get to this. I looked a the code thinking it would be relatively simple, but I don't see where we are for some reason omitting that id. Could you please put together a test or a reproduction?

@diogomrts
Copy link
Contributor Author

diogomrts commented Dec 3, 2024

I have added to this test_repo, please take a look at the Generic resource's /v1/generic endpoint

https://github.com/diogomrts/test_repo

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants