diff --git a/src/Parameters/BodyParameterGenerator.php b/src/Parameters/BodyParameterGenerator.php index 26ea1b3..d7b6822 100644 --- a/src/Parameters/BodyParameterGenerator.php +++ b/src/Parameters/BodyParameterGenerator.php @@ -105,6 +105,10 @@ protected function getNewPropObj($type, $rules) $propObj['enum'] = $enums; } + if ($format = $this->getFormatValue($rules)) { + $propObj['format'] = $format; + } + if ($type === 'array') { $propObj['items'] = []; } elseif ($type === 'object') { diff --git a/src/Parameters/Concerns/GeneratesFromRules.php b/src/Parameters/Concerns/GeneratesFromRules.php index 16f60cb..cfff667 100644 --- a/src/Parameters/Concerns/GeneratesFromRules.php +++ b/src/Parameters/Concerns/GeneratesFromRules.php @@ -46,6 +46,15 @@ protected function getArrayKey($param) return current(explode('.', $param)); } + protected function getFormatValue(array $paramRules) + { + if (in_array('date', $paramRules)) { + return 'date'; + } + + return false; + } + protected function getEnumValues(array $paramRules) { $in = $this->getInParameter($paramRules); diff --git a/tests/Parameters/BodyParameterGeneratorTest.php b/tests/Parameters/BodyParameterGeneratorTest.php index 889f48f..0a1d2e0 100644 --- a/tests/Parameters/BodyParameterGeneratorTest.php +++ b/tests/Parameters/BodyParameterGeneratorTest.php @@ -47,6 +47,15 @@ public function testRequiredParameters() */ public function testDataTypes($bodyParameters) { + //Just testing types here + $properties = array_map(function ($property) { + if (!array_key_exists('type', $property)) { + return []; + } + + return ['type' => $property['type']]; + }, $bodyParameters['schema']['properties']); + $this->assertEquals([ 'id' => ['type' => 'integer'], 'email' => ['type' => 'string'], @@ -55,7 +64,7 @@ public function testDataTypes($bodyParameters) 'picture' => ['type' => 'string'], 'is_validated' => ['type' => 'boolean'], 'score' => ['type' => 'number'], - ], $bodyParameters['schema']['properties']); + ], $properties); } public function testNoRequiredParameters() @@ -79,6 +88,20 @@ public function testEnumInBody() ], $bodyParameters['schema']['properties']); } + public function testDateFormatInBody() + { + $bodyParameters = $this->getBodyParameters([ + 'account_type' => 'date', + ]); + + $this->assertEquals([ + 'account_type' => [ + 'type' => 'string', + 'format' => 'date', + ], + ], $bodyParameters['schema']['properties']); + } + public function testArraySyntax() { $bodyParameters = $this->getBodyParameters([