e0ipso / schema-forms-php

Creates form definitions from JSON Schema property definitions and display configuration.
GNU General Public License v2.0
6 stars 2 forks source link

Loosen validation to fix error with empty objects #38

Open feuerwagen opened 5 months ago

feuerwagen commented 5 months ago

When using this library with the Drupal sdc_display module, it chokes on YAML structures like:

props:
  type: object
  properties: {}

where it's not able to recognise the value of properties as valid. This is for two reasons:

  1. The value gets deserialised as an empty array, which fails strict validation
  2. Even if validation with type cast is enabled, it still fails because (bool) $data->properties is false (see JsonFormValidator, line 27)

Steps to reproduce

See issue for Single Directory Components: Display.

Package Versions

Proposed resolution

  1. Use Constraint::CHECK_MODE_TYPE_CAST in FormGeneratorDrupal, line 52.
  2. Remove (bool) $data->properties from JsonFormValidator, line 27.

I'm well aware that this might not be the correct solution and might have implications I can't see right now. Please advise.