knuckleswtf / knuckleswtf/scribe

Extended form requests

Open
#1,070 1 comment 0 reactions 0 assignees View on GitHub
question triage
Dominant language
PHP
Stars
2.3k
Forks
357
PR merge metrics
No merged PRs in 30d

Description

### Scribe version

5.9.0

### Your question

We have a 'base' form request that is extended by a few others which is used like below

```
/**
* @var string
*/
protected string $type;

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'first_run' => 'boolean|prohibits:last_update_date',
'last_update_date' => 'nullable|date_format:Y-m-d H:i:s',
];
if (isset($this->type)) {
$rules['last_update_date'] = $rules['last_update_date'] . '|prohibits:'.$this->type;
$rules[$this->type] = 'nullable|array|prohibits:last_update_date';
}

return $rules;
}
```

with another request using it as per below

```
class QuestionUpdateRequest extends BaseUpdateRequest
{
protected function prepareForValidation()
{
$this->type = 'questions';
}

public function bodyParameters(): array
{
return array_merge(parent::bodyParameters(), [
'questions' => [
'description' => 'Array of question ID`s the application already has installed along with the dates last modified',
'example' => [
'1' => '2024-08-10 12:00:01',
'149' => '2024-07-28 10:40:01',
'3051' => '2024-09-31 15:10:06'
]
],
]);
}
}
```

Only the first defined set of rules get output, not the type specific ones or inside the if statement. How can I get these all to appear?

### Docs

- [x] I've checked [the docs](https://scribe.knuckles.wtf/laravel), the [troubleshooting guide](https://scribe.knuckles.wtf/laravel/troubleshooting), and [existing issues](https://github.com/knuckleswtf/scribe/issues?q=is%3Aissue+), but I didn't find a solution

Contributor guide

Open the contributing guide

Research direction

Reproduce the generated documentation with the BaseUpdateRequest and QuestionUpdateRequest examples, then trace how inherited form-request rules are collected. Verify whether rules defined in the base request, including the conditional type-specific rules, are included; done means all applicable rules appear in the generated API documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.