Skip to content

When a parameter is missing the error is returned without a source #93

Open
@JoeWoodward

Description

@JoeWoodward

Currently when my model validates a value that was completely excluded from the payload I get a response with empty pointers.

{
  "errors": [
    {
      "title": "Invalid user_id",
      "detail": "User can't be blank",
      "source": {}
    }
  ],
  "jsonapi": {
    "version": "1.0"
  }
}

In rails we know the source ahead of time. If it's not a query parameter then it must be a pointer.

3 situations...
resource :user, only: :show and no id is passed or we return 404 error
/url?page=1 we would either not require it or return a custom error
Missing payload attribute we should automatically infer the expected type and value of the source object e.g. source = { pointer: '/data/attributes/user_id}

This would then return

{
  "errors": [
    {
      "title": "Invalid user_id",
      "detail": "User can't be blank",
      "source": {
        "pointer": "/data/attributes/user_id"
      }
    }
  ],
  "jsonapi": {
    "version": "1.0"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions