Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
It seems that fields of type "Number (float)" are not currently supported by this module.
This message appears in watchdog when trying to view schema for a float field:
float is not a valid type for a JSON document.
Steps to reproduce
Create an entity with a "Number (float)" field and look at the schema of that field. It is null
.
Proposed resolution
TBD
Remaining tasks
TBD
User interface changes
None.
API changes
None.
Data model changes
Provide proper JSON Schema for float values.
Comment | File | Size | Author |
---|---|---|---|
#4 | 3256795-4.patch | 709 bytes | m.stenta |
Comments
Comment #2
m.stentaI spent a little time digging into this with XDebug. I found the following line in
class DataDefinitionNormalizer
:const JSON_TYPES = ['null', 'boolean', 'string', 'number', 'integer', 'array', 'object'];
https://git.drupalcode.org/project/jsonapi_schema/-/blob/4f4f1b18fd9fe8f...
This gets used in that class's
normalize()
method:https://git.drupalcode.org/project/jsonapi_schema/-/blob/4f4f1b18fd9fe8f...
It seems that adding
float
to theJSON_TYPES
array fixes the issue... sort of... instead ofnull
the schema for my float field is now:However,
"type": "float"
is not a valid JSON Schema type. According to https://json-schema.org/understanding-json-schema/reference/numeric.html, float should be"type": "number"
.I could add a simple conditional in that class to convert
float
tonumber
, but that's probably not the "correct" place to handle this.If anyone can point me in the right direction I'm happy to provide a patch! :-)
Comment #3
m.stentaComment #4
m.stentaHere is a ROUGH patch that does this. But as described above, I don't think this is the "correct" approach. Nevertheless, the patch is a quick fix for anyone who needs it (can be applied via
cweagans/composer-patches
).Comment #6
bradjones1