- Issue created by @agentrickard
- πΊπΈUnited States agentrickard Georgia (US)
I suspect this is a core issue, since the JsonSchema/Validator component says:
Validates the given data against the schema and returns an object containing the results Both the php object and the schema are supposed to be a result of a json_decode call. The validation works as defined by the schema proposal in http://json-schema.org.
- πΊπΈUnited States agentrickard Georgia (US)
Here's what is being returned from core:
// Validator::arrayToObjectRecursive stringifies the props using the JSON // encoder. Before that happens, we want to validate classes. Once the // classes are validated, we remove them as potential problems for the JSON // Schema validation. [ $schema, $props_raw, ] = $this->validateClassProps($schema, $props_raw, $component_id); $schema = Validator::arrayToObjectRecursive($schema); $props = Validator::arrayToObjectRecursive($props_raw);
$props_raw:
array(6) { ["title"]=> string(24) "Item with link and image" ["title_suffix"]=> string(13) "["foo","bar"]" ["image"]=> string(163) "{"type":"url","url":"https://designsystem.digital.gov/img/introducing-uswds-2-0/built-to-grow--alt.jpg","alt":"USWDS Card alt text","title":"USWDS Card alt title"}" ["url"]=> string(11) "my-test-url" ["date"]=> string(24) "2024-02-04T15:00:00.000Z" ["attributes"]=> NULL }
$props:
object(stdClass)#1762 (6) { ["title"]=> string(24) "Item with link and image" ["title_suffix"]=> string(13) "["foo","bar"]" ["image"]=> string(163) "{"type":"url","url":"https://designsystem.digital.gov/img/introducing-uswds-2-0/built-to-grow--alt.jpg","alt":"USWDS Card alt text","title":"USWDS Card alt title"}" ["url"]=> string(11) "my-test-url" ["date"]=> string(24) "2024-02-04T15:00:00.000Z" ["attributes"]=> NULL }
So it appears that we may need to transform the string to JSON prior to that call.
- πΊπΈUnited States agentrickard Georgia (US)
Just taking notes at this point. This almost works -- the schema now validates, but the $image element no longer renders.
// Validator::arrayToObjectRecursive stringifies the props using the JSON // encoder. Before that happens, we want to validate classes. Once the // classes are validated, we remove them as potential problems for the JSON // Schema validation. [ $schema, $props_raw, ] = $this->validateClassProps($schema, $props_raw, $component_id); foreach ($props_raw as $id => $prop) { if (is_string($prop)) { $decoded = json_decode($prop); if ($decoded !== NULL && $decoded !== $prop) { $props_raw[$id] = $decoded; } } } $schema = Validator::arrayToObjectRecursive($schema); $props = Validator::arrayToObjectRecursive($props_raw);
- πΊπΈUnited States agentrickard Georgia (US)
This may be a duplicate of π String value found, but an array or an object is required RTBC but it is very difficult to see where the issue should be fixed.
- Status changed to Closed: duplicate
10 months ago 3:41pm 22 February 2024