api-platform / api-platform/core
[JSON:API] Errors format does not follow specification
- 主要語言
- PHP
- 星號
- 2.6k
- 分支
- 980
- 平均合併
- 2 天 2 小時
- 30 天內合併 PR
- 51
描述
**PHP version:** 7.2
**Symfony version:** 4.3.1
**API-Platform version:** 2.4.5
### How to reproduce
- Configure API Platform to use `jsonapi` as default payload serializer
- Perform any request that throws an Exception
_Example:_
Perform a request that will throw an HTTP 400 error due to validation constraint failed
### Expected behavior
Error payload respects these following statements (from JSON:API specification on [error format](https://jsonapi.org/format/#error-objects) and [server-side content negotiation](https://jsonapi.org/format/#content-negotiation-servers)):
> - Servers MUST send all JSON:API data in response documents with the header Content-Type: application/vnd.api+json without any media type parameters.
[...]
> - Error objects MUST be returned as an array keyed by errors in the top level of a JSON:API document.
> - An error object MAY have the following members:
> - id: a unique identifier for this particular occurrence of the problem.
> - links: a links object containing the following members:
> - about: a link that leads to further details about this particular occurrence of the problem.
> - status: the HTTP status code applicable to this problem, expressed as a string value.
> - code: an application-specific error code, expressed as a string value.
> - title: a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
> - detail: a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be localized.
> - source: an object containing references to the source of the error, optionally including any of the following members:
> - pointer: a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].
> - parameter: a string indicating which URI query parameter caused the error.
> - meta: a meta object containing non-standard meta-information about the error.
_Example:_
Response header `Content-Type` is `application/vnd.api+json`
```json
{
"errors": [
"links": {
"about": "https://tools.ietf.org/html/rfc2616#section-10"
},
"title": "An error occurred",
"detail": "countryCode: This value is not a valid country.",
"source": {
"pointer": "data/attributes/countryCode"
}
"meta": {
"violations": [
{
"propertyPath": "countryCode",
"message": "This value is not a valid country."
}
]
}
]
}
```
### Actual behavior
Error follows the [RFC 7807](https://tools.ietf.org/html/rfc7807) HTTP Problem specification, which is not compatible with JSON:API error format specs
_Example:_
Response header `Content-Type` is `application/problem+json; charset=utf-8`
```json
{
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"detail": "countryCode: This value is not a valid country.",
"violations": [
{
"propertyPath": "countryCode",
"message": "This value is not a valid country."
}
]
}
```
---
I would be glad to submit a PR to fix this, but I'm not experienced enough with API Platform Core development. Help from fellow contributors would be very much appreciated :100:
貢獻指南
評估
這個 Issue 還沒有評估資料。