Skip to content

Fix error handling for sparse fieldsets #2

@tpansino

Description

@tpansino

Assume we have a JSON API endpoint called /users with a first_name attribute on the resource object.

The JSON API spec says that GET /users?fields[user]=first_name should return a sparse array of user objects with only the first_name attribute in the objects.

What actually happens currently is all attributes are returned, the fields[users] parameter is ignored, because the code currently matches against fields[user] instead. Furthermore, there's no feedback to a developer to indicate that the requested fields[.*] parameter is actually invalid and the request is bad.

Expected behavior:

  • fields[users]=first_name should return HTTP 200 with a list of people with first_name as the only attribute in the payload
  • fields[user]=first_name should return HTTP 400 with a payload error indicating that the fields[user] is invalid

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