diff --git a/composer.json b/composer.json index 1d4a380..12888f8 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,17 @@ } ], "repositories": [ - {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/php-kafka-schema-registry-client.git"} + { + "type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/php-kafka-schema-registry-client.git" + } ], "require": { + "ext-json": "*", "flix-tech/avro-php": "^3.0|^4.0", "symfony/console": "^4.3|^5.1", "pimple/pimple": "^3.2", "jobcloud/php-kafka-schema-registry-client": "^0.1", - "guzzlehttp/guzzle": "^6.3|^7.3", - "ext-json": "*" + "guzzlehttp/guzzle": "^6.3|^7.3" }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/docker/dev/php/Dockerfile b/docker/dev/php/Dockerfile index 16b1ebe..3c152e2 100644 --- a/docker/dev/php/Dockerfile +++ b/docker/dev/php/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.3-cli-alpine3.13 +FROM php:7.3-cli-alpine3.14 ARG HOST_USER_ID diff --git a/src/Command/CheckAllSchemaTemplatesDefaultTypeCommand.php b/src/Command/CheckAllSchemaTemplatesDefaultTypeCommand.php index b917169..55596b2 100644 --- a/src/Command/CheckAllSchemaTemplatesDefaultTypeCommand.php +++ b/src/Command/CheckAllSchemaTemplatesDefaultTypeCommand.php @@ -28,8 +28,8 @@ protected function configure(): void { $this ->setName('kafka-schema-registry:check:template:default:type:all') - ->setDescription('Checks for default value type for all schema templates in folder') - ->setHelp('Checks for default value type for all schema templates in folder') + ->setDescription('Checks if default type is the first type in union for all schema templates in folder') + ->setHelp('Checks if default type is the first type in union for all schema templates in folder') ->addArgument( 'schemaTemplateDirectory', InputArgument::REQUIRED, @@ -122,8 +122,8 @@ private function checkAllFields($decodedSchema, array $defaultFields = []): arra $fieldTypes = [$fieldTypes]; } - foreach ($fieldTypes as $fieldType) { - $defaultFields = $this->checkSingleField($fieldType, $field, $defaultFields); + if (count($fieldTypes)) { + $defaultFields = $this->checkSingleField($fieldTypes[0], $field, $defaultFields); } } diff --git a/tests/Command/CheckAllSchemaTemplatesDefaultTypeCommandTest.php b/tests/Command/CheckAllSchemaTemplatesDefaultTypeCommandTest.php index a87a380..dff80a7 100644 --- a/tests/Command/CheckAllSchemaTemplatesDefaultTypeCommandTest.php +++ b/tests/Command/CheckAllSchemaTemplatesDefaultTypeCommandTest.php @@ -29,13 +29,13 @@ class CheckAllSchemaTemplatesDefaultTypeCommandTest extends AbstractSchemaRegist }, { "name": "name2", - "type": ["null","string"], + "type": ["string","null"], "default": "", "doc": "some desc" }, { "name": "bool1", - "type": ["null","boolean"], + "type": ["boolean","null"], "default": false, "doc": "some desc" }, @@ -57,19 +57,25 @@ class CheckAllSchemaTemplatesDefaultTypeCommandTest extends AbstractSchemaRegist "doc": "some desc" }, { - "name": "number3", + "name": "number4", "type": ["double","float"], "default": 0, "doc": "some desc" }, + { + "name": "number5", + "type": ["float","int"], + "default": 0, + "doc": "some desc" + }, { "name": "array1", "type": [ - "null", { "type": "array", "items": "ch.jobcloud.item" - } + }, + "null" ], "default": [], "doc": "some desc" @@ -105,7 +111,7 @@ class CheckAllSchemaTemplatesDefaultTypeCommandTest extends AbstractSchemaRegist { "name": "name2", "type": ["null","string"], - "default": "", + "default": "VALUE", "doc": "some desc" }, {