Reference
Diagnostics
The findings of jsonapi:check and ResourceAssertions, and how to fix them.
Found when a definition is compiled or by the check of ark4ne/laravel-api-revisions (whose own codes, such as
conversion-missing, are documented there). An error fails the check; a warning fails it with --strict /
strict: true.
| Code | Level | Cause and fix |
|---|---|---|
definition-error | error | The values cannot be compiled: a plain value or a member without name in a hook, a hook throwing on the probe (an if on the model, a call on a relation), a relationship to a class that is not a resource, an invalid history. Rendering throws a DefinitionException |
hook-failure | error | toLinks() threw on the probe, or holds a descriptor |
invalid-resource | error | The class is not a resource, its type cannot be read, or it exists at no revision |
jsonapi-reserved-name | error | An attribute or a relationship named id or type at the revision |
jsonapi-name-collision | error | An attribute and a relationship with one name at the revision: bound them with until() / since() |
jsonapi-absent-resource | error | A relationship reaches, at the revision, a resource absent from it (#[JsonApiSince] without was() for older revisions) |
missing-route | error | The self route of #[JsonApiRoutes] does not exist |
load-conflict | warning | Two relationships load the same relation with different withLoad() constraints |
filter-on-unloaded | warning | ->filters() on a relation that is not loaded, read resource by resource: let it load |
load-conflict and filter-on-unloaded are found while rendering too, in debug only, in the diagnostics of the
JsonApiContext.
When the document is wrong
| Symptom | Cause and fix |
|---|---|
| A member is missing | Left out by fields[type], by its condition, or empty (attributes, meta… are left out when empty) |
fields / include rejected for a member that exists | It is added under an if: use ->when() or applyWhen() |
data missing on a relationship | relationship.linkage is included or loaded, or the relationship has ->whenIncluded() / ->whenLoaded() |
| One query per resource | The relationship is read by a closure: use $this->many(PostResource::class), or ->withLoad('posts') |
| A value has the wrong type | Use the matching descriptor (integer(), datetime(), decimal(), enum()…) |
| A date lost its time | date() is a date without time: use datetime() |
RenderingException | The identifier is neither an integer nor a string, or the resource does not exist at the revision |
| The error body is Laravel's | JsonApi::renderErrors() is not called, or the request does not expect JSON |