Skip to content

Commit

Permalink
Merge pull request #511 from leandrodiogenes/master
Browse files Browse the repository at this point in the history
[Feature] No-example value with formRequest bodyParameter and queryPameters
  • Loading branch information
shalvah authored Aug 25, 2022
2 parents a739d24 + cec35ef commit 6104942
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Extracting/ParsesValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ protected function getParameterExample(array $parameterData)
: null;
}
} else if (!is_null($parameterData['example']) && $parameterData['example'] !== self::$MISSING_VALUE) {
if($parameterData['example'] === 'No-example' && !$parameterData['required']){
return null;
}
// Casting again is important since values may have been cast to string in the validator
return $this->castToType($parameterData['example'], $parameterData['type']);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/TestRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function rules()
'user_id' => 'int|required',
'room_id' => ['string'],
'forever' => 'boolean',
'no_example_attribute' => 'numeric',
'another_one' => 'numeric',
'even_more_param' => 'array',
'book.name' => 'string',
Expand Down Expand Up @@ -59,6 +60,10 @@ public function bodyParameters()
'another_one' => [
'description' => 'Just need something here.',
],
'no_example_attribute' => [
'description' => 'Attribute without example.',
'example' => 'No-example',
],
'even_more_param' => [
'description' => '',
],
Expand Down
6 changes: 6 additions & 0 deletions tests/Strategies/GetFromFormRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function can_fetch_bodyparams_from_form_request()
'required' => false,
'description' => 'Just need something here.',
],
'no_example_attribute' => [
'type' => 'number',
'required' => false,
'description' => 'Attribute without example.',
'example' => null,
],
'even_more_param' => [
'type' => 'string[]',
'required' => false,
Expand Down

0 comments on commit 6104942

Please sign in to comment.