From 523187f19446945c38b64d806bca42da09771a69 Mon Sep 17 00:00:00 2001 From: Jakob-Espersen Date: Thu, 16 Jan 2025 11:04:30 +0100 Subject: [PATCH 1/2] dont clean the database type if it is tinyint(1) and should be a boolean instead --- src/Definitions/DefinitionGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Definitions/DefinitionGenerator.php b/src/Definitions/DefinitionGenerator.php index 235c28f..ef3afad 100644 --- a/src/Definitions/DefinitionGenerator.php +++ b/src/Definitions/DefinitionGenerator.php @@ -294,7 +294,7 @@ private function cleanDatabaseType(string $dbType) private function convertDBTypeToSwaggerType(string $dbType): array { // We use preg_replace to remove parenthesis, eg: "int(20)" become just "int" - $lowerType = $this->cleanDatabaseType($dbType); + $lowerType = $dbType == 'tinyint(1)' ? 'boolean' : $this->cleanDatabaseType($dbType); switch ($lowerType) { case 'bigserial': case 'bigint': From a9ce602d524b03027d41ecb4cca4e81db53216a2 Mon Sep 17 00:00:00 2001 From: Jakob-Espersen Date: Thu, 16 Jan 2025 11:11:36 +0100 Subject: [PATCH 2/2] readability --- src/Definitions/DefinitionGenerator.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Definitions/DefinitionGenerator.php b/src/Definitions/DefinitionGenerator.php index ef3afad..aa1ba35 100644 --- a/src/Definitions/DefinitionGenerator.php +++ b/src/Definitions/DefinitionGenerator.php @@ -292,9 +292,11 @@ private function cleanDatabaseType(string $dbType) * @return array array of with 'type' and 'format' as keys */ private function convertDBTypeToSwaggerType(string $dbType): array - { - // We use preg_replace to remove parenthesis, eg: "int(20)" become just "int" - $lowerType = $dbType == 'tinyint(1)' ? 'boolean' : $this->cleanDatabaseType($dbType); + { + $lowerType = $dbType == 'tinyint(1)' + ? 'boolean' // tinyint(1) is a boolean + : $this->cleanDatabaseType($dbType); // We use preg_replace to remove parenthesis, eg: "int(20)" become just "int" + switch ($lowerType) { case 'bigserial': case 'bigint':