Steps to reproduce:
- Drupal 8.5.1 + php 7.1
- Install drupal with standard profile
- Install jsonapi + schemata_json_schema modules
- access to /jsonapi/node/page (OK)
- create a page node
- access to /jsonapi/node/page (KO)
The website encountered an unexpected error. Please try again later.
AssertionError: A JSON API response failed validation (see the logs for details). Please report this in the issue queue on drupal.org in assert() (line 182 of modules/contrib/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php).
assert(, 'A JSON API response failed validation (see the logs for details). Please report this in the issue queue on drupal.org') (Line: 182)
Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->doValidateResponse(Object, Object) (Line: 172)
Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->onResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 191)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 173)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 40)
Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comments
Comment #2
akalam commentedComment #3
e0ipso@akalam can you share the validation error present in your logs?
Comment #4
alesbencina commentedMight be a problem related to schemata module. Which version are you using and schema?
Comment #5
akalam commented@e0ipso
Here the validation messages present in the error log.
For more legible messages, I paste the unserialized error messages:
@alesbencina I'm ussing schemata last release 1.0-alpha3
Comment #6
wim leersSchemata just had a new release. That could be it.
It's not milliseconds, but seconds, so this is wrong in the schema.
This is optional, so
NULLis valid.Same here.
Pinged the
schematamaintainer: https://twitter.com/wimleers/status/981550577535651840.Comment #7
logickal commentedJust to chime in here, we are also seeing this after upgrading jsonapi. I agree that the issue looks like the schema that Schemata generates is wrong based on entity and fields as configured, but not sure that it's just their latest version, as I tested against their commits from October and still failed. We are going to try to take a look at the schema generation and type_mappers and see if we can find some clues there.
Comment #8
wim leersInteresting! We're very confident we didn't change JSON API response documents thanks to our test coverage —
git d 8.x-1.14 8.x-1.15 -- tests/src/Functionalwould have to show significant changes if we'd broken BC in JSON API.It'd be wonderful if you could dig into this and determine the root cause! 👍
Comment #9
brockfanning commentedI'm new to this suite of modules, but a couple thoughts based on what I've found so far:
assert_options(ASSERT_ACTIVE, TRUE);Comment #10
wim leers@brockfanning: Welcome, and thank you for opening #2958251: Allow null value for non-required fields (json schema). I can confirm that your statement about
ASSERT_ACTIVEis correct :)Comment #11
Grayside commentedThanks for pinging me Wim.
Schemata was overdue for a release for some time, is there confirmation this was working with Schemata alpha2?
Comment #12
e0ipsoComment #13
wim leersCan somebody who's affected by this please test that? Thanks!
Comment #14
brockfanning commentedI just tested with Schemata 1.0-alpha2, JSON API 1.14, and JSON API Extras 2.0-rc1 - and I'm seeing similar errors as above - such as the langcode ("object is required"), created/changed (milliseconds vs seconds), and the fields not accepting NULL values.
I also tested with Schemata 1.0-alpha3, JSON API 1.15, and JSON API Extras 2.0-rc1 - and I get the same results.
One possible reason for differing experiences might be that the appearance of errors is affected by the "fields" query parameter. For example, if my GET request includes
&fields[my_content_type]=title,changedthen I will see the validation error about milliseconds for 'changed', but if my GET request only includes&fields[my_content_type]=titlethen I won't see that validation error.A side note: This effect of the "fields" query parameter can also cause issues when required fields are not included in the parameter value. For example, if my content type has a required field called "foo", and my GET request includes
&fields[my_content_type]=title,foothen I won't see any validation errors. But if my GET request only includes&fields[my_content_type]=titlethen I will see a validation error about foo being required.Comment #15
wim leersClosed #2958899: Type 'uri' not valid in JsonSchema as a duplicate.
Comment #16
brockfanning commentedHopefully I haven't misinterpreted something in my testing, but I think this problem stems from dependencies of jsonapi_extras:2.0.0-rc1. When I revert to jsonapi_extras:1.0.0-rc7 the validation errors go away. I can clearly see that when I do a `composer install` after upgrading to jsonapi_extras:2.0.0-rc1, the justinrainbow/json-schema package is installed, and when I revert back to 1.0.0-rc7, the justinrainbow/json-schema package is removed. I believe this is caused by e0ipso/shaper, which has a dependency on json-schema:^5.2 (https://github.com/e0ipso/shaper/blob/master/composer.json#L20).
I'll go out on a limb and move this to the jsonapi_extras 2.0 queue, but feel free to move it back if I'm off base.
Comment #17
wim leers@brockfanning: Thanks so much for digging into this!
Comment #18
s_leu commentedHad the same problem. Atfer updating the following modules to these versions, it was gone:
Comment #19
logickal commentedI think this is resolved with the latest 1.x of jsonapi and 2.x of jsonapi_extras as noted above by @s_leu. We have re-enabled schemata and openapi modules and are no longer seeing validation errors.
Comment #20
e0ipsoFantastic! Thanks for the feedback @s_leu and @logickal!
I'll close this issue then.
Comment #21
e0ipsoComment #22
wim leers🎉
Comment #23
e0ipsoFWIW I suspect that the fix was a patch to Schemata. I already released that patch in tagged version, so you don't have to rely in `1.x-dev`.