diff --git a/src/Extracting/ParamHelpers.php b/src/Extracting/ParamHelpers.php index 426d33b5..a8125bab 100644 --- a/src/Extracting/ParamHelpers.php +++ b/src/Extracting/ParamHelpers.php @@ -250,8 +250,8 @@ protected function parseExampleFromParamDescription(string $description, string $description = trim($content[1]); $enumValues = array_map( - fn ($value) => $this->castToType($value, $type), - explode($content[2], ',') + fn ($value) => $this->castToType(trim($value), $type), + explode(',', rtrim(trim($content[2]), '.')) ); } diff --git a/tests/Strategies/BodyParameters/GetFromBodyParamAttributeTest.php b/tests/Strategies/BodyParameters/GetFromBodyParamAttributeTest.php index 6669063f..93c90be0 100644 --- a/tests/Strategies/BodyParameters/GetFromBodyParamAttributeTest.php +++ b/tests/Strategies/BodyParameters/GetFromBodyParamAttributeTest.php @@ -89,6 +89,12 @@ public function can_fetch_from_bodyparam_attribute() 'description' => '', 'required' => true, ], + 'state' => [ + 'type' => 'string', + 'description' => '', + 'required' => true, + 'enumValues' => ["active", "pending"] + ], 'users' => [ 'type' => 'object[]', 'description' => 'Users\' details', @@ -216,6 +222,7 @@ class BodyParamAttributeTestController #[BodyParam("book.author_id", type: "integer")] #[BodyParam("book.pages_count", type: "integer")] #[BodyParam("ids", "integer[]")] + #[BodyParam("state", enum: ["active", "pending"])] #[BodyParam("users", "object[]", "Users' details", required: false)] #[BodyParam("users[].first_name", "string", "The first name of the user.", example: "John", required: false)] #[BodyParam("users[].last_name", "string", "The last name of the user.", example: "Doe", required: false)] diff --git a/tests/Strategies/GetFromInlineValidatorTest.php b/tests/Strategies/GetFromInlineValidatorTest.php index 8d4d9d93..4235b598 100644 --- a/tests/Strategies/GetFromInlineValidatorTest.php +++ b/tests/Strategies/GetFromInlineValidatorTest.php @@ -26,7 +26,7 @@ class GetFromInlineValidatorTest extends BaseLaravelTest 'room_id' => [ 'type' => 'string', 'required' => false, - 'description' => 'The id of the room. Must be one of 3, 5, or 6.', + 'description' => 'The id of the room.', ], 'forever' => [ 'type' => 'boolean', @@ -193,12 +193,12 @@ public function can_fetch_inline_enum_rules() $expected = [ 'enum_class' => [ 'type' => 'string', - 'description' => 'Must be one of red, green, or blue.', + 'description' => '', 'required' => true, ], 'enum_string' => [ 'type' => 'string', - 'description' => 'Must be one of 1, 2, or 3.', + 'description' => '', 'required' => true, ], 'enum_inexistent' => [ diff --git a/tests/Unit/ValidationRuleParsingTest.php b/tests/Unit/ValidationRuleParsingTest.php index 2380162f..10ba7e4b 100644 --- a/tests/Unit/ValidationRuleParsingTest.php +++ b/tests/Unit/ValidationRuleParsingTest.php @@ -68,8 +68,8 @@ public function can_parse_rule_objects() 'in_param' => ['numeric', Rule::in([3,5,6])] ]); $this->assertEquals( - 'Must be one of 3, 5, or 6.', - $results['in_param']['description'] + [3, 5, 6], + $results['in_param']['enumValues'] ); } @@ -228,8 +228,9 @@ public static function supportedRules() ['in_param' => 'in:3,5,6'], ['in_param' => ['description' => $description]], [ - 'description' => "$description. Must be one of 3, 5, or 6.", + 'description' => $description.".", 'type' => 'string', + 'enumValues' => [3,5,6] ], ]; yield 'not_in' => [ @@ -533,8 +534,8 @@ public function can_parse_enum_rules() ]); $this->assertEquals('string', $results['enum']['type']); $this->assertEquals( - 'Must be one of red, green, or blue.', - $results['enum']['description'] + ['red', 'green', 'blue'], + $results['enum']['enumValues'] ); $this->assertTrue(in_array( $results['enum']['example'], @@ -547,8 +548,8 @@ public function can_parse_enum_rules() ]); $this->assertEquals('integer', $results['enum']['type']); $this->assertEquals( - 'Must be one of 1, 2, or 3.', - $results['enum']['description'] + [1, 2, 3], + $results['enum']['enumValues'] ); $this->assertTrue(in_array( $results['enum']['example'], @@ -562,7 +563,7 @@ public function can_parse_enum_rules() ]); $this->assertEquals('string', $results['enum']['type']); $this->assertEquals( - 'A description. Must be one of red, green, or blue.', + 'A description.', $results['enum']['description'] ); $this->assertTrue(in_array(