Closed (fixed)
Project:
JSON:API Schema
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Jan 2022 at 18:26 UTC
Updated:
28 May 2025 at 17:04 UTC
Jump to comment: Most recent, Most recent file
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
floatto theJSON_TYPESarray fixes the issue... sort of... instead ofnullthe 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
floattonumber, 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
bradjones1Comment #7
m.stentaThis also applies to decimal fields. Updating title and description accordingly.
Also, marking this as "Major" because including either of these field types in an entity bundle crashes the schema for that bundle with the following error. This may have changed recently due to upstream changes in Symfony, because I don't think I experienced this originally, but it was also reported in #3491229: Decimal field causes error message on custom entity.
I've learned a lot about how this module works since I posted the patch in #4. The correct approach is to provide a new normalizer class that declares supported types of
decimalandfloat. I will open a merge request with tests shortly...Comment #9
m.stentaComment #11
m.stenta