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

JSON:API spec compliance when creating resources - The resource object MUST contain at least a type member. #164

Open
sevenseacat opened this issue Jun 12, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@sevenseacat
Copy link
Contributor

Describe the bug

From: https://jsonapi.org/format/#crud-creating

A resource can be created by sending a POST request to a URL that represents a collection of resources. The request MUST include a single resource object as primary data. The resource object MUST contain at least a type member.

Something small I noticed - we don't require that the type member is present in the request.

We do validate it if it is present (empty/invalid values return an error) but if it's omitted, records can still be created.

Screenshot 2024-06-12 at 6 19 11 PM

To Reproduce

A json_api config and :

  json_api do
    type "artist"

    routes do
      base "/artists"

      post :create
    end
  end

  actions do
    create :create do
      accept [:name, :biography]
      change relate_actor(:created_by, allow_nil?: true)
      change relate_actor(:updated_by, allow_nil?: true)
    end
  end

Expected behavior

For full compliance with the spec, an error should also be returned if the type is not provided as part of the data hash. This would probably be a breaking change even though it's to add compliance 🤔

Runtime

  • Elixir version 1.17.0-rc.1
  • Erlang version 27.0
  • OS macOS Sonoma
  • Ash version 3.0.11
  • AshJsonApi version 1.2.0
@sevenseacat sevenseacat added bug Something isn't working needs review labels Jun 12, 2024
@sevenseacat sevenseacat changed the title When creating resources - The resource object MUST contain at least a type member. JSON:API spec compliance when creating resources - The resource object MUST contain at least a type member. Jun 12, 2024
@zachdaniel
Copy link
Contributor

Yeah, realistically it's not something we can change now unless we put it behind some kind of strict flag. I wouldn't be opposed to that. In general we always know the type of something at all times, so it would only be for spec compliance not for anything that we need.

@zachdaniel zachdaniel added good first issue Good for newcomers and removed needs review labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants