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

Throw Exception if 'data' and 'errors' coexist in the request body #98

Closed
Art4 opened this issue Jul 17, 2020 · 3 comments
Closed

Throw Exception if 'data' and 'errors' coexist in the request body #98

Art4 opened this issue Jul 17, 2020 · 3 comments

Comments

@Art4
Copy link
Contributor

Art4 commented Jul 17, 2020

Hello and thank you for this great library.

I have noticed a behavior that is against the JSON:API spec.

The top level document could contain a data or errors attribute, but both MUST NOT coexist in the same document. See https://jsonapi.org/format/1.0/#document-top-level
While this is never the case in the response, it can also occur in the request.

What I do:

As an example let one send the following request:

POST https://api.example.com/posts

{
  "data": {
    "type": "posts",
    "attributes": {
      "content": "Lorem ipsum dolor sit amet, sed libris elaboraret eu."
    }
  },
  "errors": [
    {
      "detail": "The members data and errors MUST NOT coexist in the same document."
      "links": {
        "about": "https://jsonapi.org/format/1.0/#document-top-level"
      }
    }
  ]
}

What happend:

The server accepted the request.

What I expect:

The Server refuses the request because the body does not contain valid JSON:API.

@kocsismate
Copy link
Member

@Art4 Thank you very much for reporting the issue! I can confirm, this validation is currently missing from the library. I'll implement it in the following week(s), but you can also do so if you are up to prepare a PR. :)

@Art4 Art4 closed this as completed Jul 19, 2020
@Art4 Art4 reopened this Jul 19, 2020
@Art4
Copy link
Contributor Author

Art4 commented Jul 19, 2020

I'm glad if I could help with a PR but I need a little help for the right place to implement. I also assume we would need a new exception class?

@kocsismate
Copy link
Member

I also assume we would need a new exception class?

Right! Additionally, a new RequestValidator::validateBody() method should throw it by using the ExceptionFactoryInterface. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants