From cb6290cec8dac70ca879499d54528e3d011e6c43 Mon Sep 17 00:00:00 2001 From: Hajime MATSUMOTO <55294484+HajimeMat-AVAP@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:03:46 +0900 Subject: [PATCH 1/2] Update TypeResolver.php To Accept openapi type like ``` - string - null ``` becouse API DOG generate like this if i allow null to params. logic is like if type is array and just have a 2 choice and 1 is "null" that means the type is the onather nullable. so I changed --- src/Generator/TypeResolver.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Generator/TypeResolver.php b/src/Generator/TypeResolver.php index ca96722..8c377c8 100644 --- a/src/Generator/TypeResolver.php +++ b/src/Generator/TypeResolver.php @@ -64,7 +64,12 @@ public function resolve( return Types::Enum; } - $type = match ($schema->type) { + $schemaType = $schema->type; + if (is_array($schema->type) && count($schema->type) == 2 && in_array("null", $schema->type)) { + $schemaType = current( array_filter($schema->type, fn ($x) => $x !== 'null')); + } + + $type = match ($schemaType) { 'number' => match ($schema->format) { 'double', 'float' => 'float', default => 'int' From 81f00861369ffad055435247bf8ece1f5cc7a379 Mon Sep 17 00:00:00 2001 From: Hajime MATSUMOTO <55294484+HajimeMat-AVAP@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:26:48 +0900 Subject: [PATCH 2/2] Change Variable Name --- src/Generator/TypeResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator/TypeResolver.php b/src/Generator/TypeResolver.php index 8c377c8..fd5efd2 100644 --- a/src/Generator/TypeResolver.php +++ b/src/Generator/TypeResolver.php @@ -66,7 +66,7 @@ public function resolve( $schemaType = $schema->type; if (is_array($schema->type) && count($schema->type) == 2 && in_array("null", $schema->type)) { - $schemaType = current( array_filter($schema->type, fn ($x) => $x !== 'null')); + $schemaType = current( array_filter($schema->type, fn (string $type) => $type !== 'null')); } $type = match ($schemaType) {