From f1763a0259cd37ea7eb607658e4b129fe2a568e7 Mon Sep 17 00:00:00 2001 From: chris cnizzardini Date: Sat, 18 Apr 2020 23:06:08 -0400 Subject: [PATCH] Make debugging invalid data types easier --- src/Lib/Annotation/SwagForm.php | 10 ++++++---- src/Lib/Annotation/SwagQuery.php | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Lib/Annotation/SwagForm.php b/src/Lib/Annotation/SwagForm.php index 313e54e1..33f146de 100644 --- a/src/Lib/Annotation/SwagForm.php +++ b/src/Lib/Annotation/SwagForm.php @@ -27,11 +27,13 @@ public function __construct(array $values) throw new InvalidArgumentException('Name parameter is required'); } - $type = strtolower($values['type']); + $values = array_merge(['type' => 'string', 'required' => false], $values); - if (!in_array($type, OpenApiDataType::TYPES)) { + if (!in_array($values['type'], OpenApiDataType::TYPES)) { + $type = $values['type']; + $name = $values['name']; throw new SwaggerBakeRunTimeException( - "Invalid Data Type, given `$type` but must be one of: " . + "Invalid Data Type, given [$type] for [$name] but must be one of: " . implode(',', OpenApiDataType::TYPES) ); } @@ -39,7 +41,7 @@ public function __construct(array $values) $values = array_merge(['type' => 'string', 'required' => false], $values); $this->name = $values['name']; - $this->type = $type; + $this->type = $values['type']; $this->required = $values['required']; } } \ No newline at end of file diff --git a/src/Lib/Annotation/SwagQuery.php b/src/Lib/Annotation/SwagQuery.php index f1e476cc..c9f9cc5e 100644 --- a/src/Lib/Annotation/SwagQuery.php +++ b/src/Lib/Annotation/SwagQuery.php @@ -27,19 +27,19 @@ public function __construct(array $values) throw new InvalidArgumentException('Name parameter is required'); } - $type = strtolower($values['type']); + $values = array_merge(['type' => 'string', 'required' => false], $values); - if (!in_array($type, OpenApiDataType::TYPES)) { + if (!in_array($values['type'], OpenApiDataType::TYPES)) { + $type = $values['type']; + $name = $values['name']; throw new SwaggerBakeRunTimeException( - "Invalid Data Type, given `$type` but must be one of: " . + "Invalid Data Type, given [$type] for [$name] but must be one of: " . implode(',', OpenApiDataType::TYPES) ); } - $values = array_merge(['type' => $type, 'required' => false], $values); - $this->name = $values['name']; - $this->type = $type; + $this->type = $values['type']; $this->required = $values['required']; } } \ No newline at end of file