knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.59k stars 280 forks source link

Incorrect generation of Try it out #722

Closed alx-sychev closed 9 months ago

alx-sychev commented 9 months ago

Scribe version

4.23.1

PHP version

8.2.10

Framework

Laravel

Framework version

10.22.0

Scribe config

theme => "elements"
strategies.bodyParameters => removed Knuckles\Scribe\Extracting\Strategies\BodyParameters\GetFromFormRequest, Knuckles\Scribe\Extracting\Strategies\BodyParameters\GetFromInlineValidator, Knuckles\Scribe\Extracting\Strategies\BodyParameters\GetFromBodyParamTag

What happened?

I created a request with an array of objects using documentation (https://scribe.knuckles.wtf/laravel/documenting/query-body-parameters#arrays-of-objects).

I got an incorrect result in the request example: an object instead of an array of objects in the request body section, and something very strange in the JS request example.

I see that @stephane-monnot has already fixed the incorrect generation of the request body section in https://github.com/knuckleswtf/scribe/pull/720/files. But I tried to add his changes to my code, and there is a bug in the JS request example anyway.

My request:

/**
 * @bodyParam text string
 * @bodyParam answers object[]
 * @bodyParam answers.text string
 * @bodyParam answers.isRight bool
 */
class StoreQuestionRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'text' => 'required|string',
            'answers.*' => 'array',
            'answers.*.text' => 'required|string',
            'answers.*.isRight' => 'required|bool',
        ];
    }
}

Screenshot of the result:

image

Screenshot of the result (added fix):

image

Docs

alx-sychev commented 9 months ago

UPD: It will work correctly if I write answers[].text instead of just answers.text. So, the example in the documentation should be changed.

alx-sychev commented 9 months ago

I created PR in docs repo: https://github.com/knuckleswtf/scribe-docs/pull/24