diff --git a/Civi/RemoteTools/JsonSchema/FormSpec/Factory/OptionFieldFactory.php b/Civi/RemoteTools/JsonSchema/FormSpec/Factory/OptionFieldFactory.php index 766bb6b..2af1648 100644 --- a/Civi/RemoteTools/JsonSchema/FormSpec/Factory/OptionFieldFactory.php +++ b/Civi/RemoteTools/JsonSchema/FormSpec/Factory/OptionFieldFactory.php @@ -32,8 +32,16 @@ public function createSchema(AbstractFormField $field): JsonSchema { /** @var \Civi\RemoteTools\Form\FormSpec\Field\AbstractOptionField $field */ $keywords = [ 'type' => ['string', 'integer'], - 'oneOf' => JsonSchemaUtil::buildTitledOneOf($field->getOptions()), ]; + + // 'oneOf' must not be empty. + if ($field->getOptions() !== []) { + $keywords['oneOf'] = JsonSchemaUtil::buildTitledOneOf($field->getOptions()); + } + elseif (!$field->isNullable()) { + $keywords['oneOf'] = JsonSchema::fromArray(['const' => NULL]); + } + if ($field->isNullable()) { $keywords['type'][] = 'null'; $keywords['oneOf'][] = JsonSchema::fromArray(['const' => NULL]); diff --git a/Civi/RemoteTools/JsonSchema/Util/JsonSchemaUtil.php b/Civi/RemoteTools/JsonSchema/Util/JsonSchemaUtil.php index 6122204..4a15b50 100644 --- a/Civi/RemoteTools/JsonSchema/Util/JsonSchemaUtil.php +++ b/Civi/RemoteTools/JsonSchema/Util/JsonSchemaUtil.php @@ -24,10 +24,12 @@ final class JsonSchemaUtil { /** - * @phpstan-param array $titles + * The 'oneOf' keyword must not be empty. + * + * @phpstan-param non-empty-array $titles * Allowed values mapped to titles. * - * @phpstan-return array To be used as value of "oneOf" keyword. + * @phpstan-return non-empty-array To be used as value of "oneOf" keyword. */ public static function buildTitledOneOf(array $titles): array { $oneOf = [];