knuckleswtf / scribe

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

Collection with formdata malformed for API #881

Open KriKrus opened 1 month ago

KriKrus commented 1 month ago

Scribe version

4.37.1

PHP version

8.3.9

Framework

Laravel

Framework version

11.20.0

Scribe config

title => "xxx API Dokumentation"
auth.enabled => true
auth.default => true
auth.name => "Authorization"
logo => "logo.svg"
examples.faker_seed => 1234
strategies.headers => added [
    'override',
    [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'im-client-type' => 'app',
        'im-app-version' => '2024.08.14',
        'im-device-id' => 'id123',
    ],
]: removed [
    'override',
    [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],
]

What happened?

The Command generates the postman collection and I want to upload it to the postman api using the put api, but the request gets rejected because of a validation failure.

The problem is following json part in a formdata request:

{
    "key": "size",
    "value": 84,
    "type": "text",
    "description": ":Attribute muss mindestens 0 sein."
}

which is generated from following rules of a form request:


    public function rules(): array
    {
        return [
            'size' => ['required', 'numeric', 'min:0'],
        ];
    }

Postman rejects the file, because the form data is set to type "text", but the value is an integer. Can the generation of the collection respect the type? I think the change needs to be made in the PostmanCollectionWriter in getFormDataParams, if its not type file always cast the value to a string?

Docs

shalvah commented 2 weeks ago

Good catch. Could you send in a PR to fix?