knuckleswtf / scribe

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

How to override post-response script content for the postman? #850

Open hardiklakhalani opened 1 month ago

hardiklakhalani commented 1 month ago

Scribe version

4.35.0

Your question

How to override post-response script content for the postman?

Here is the script I want to add in my login request:

pm.collectionVariables.set("token", pm.response.json().data.token);

image

Following is the variables I've already overridden successfully:

But not sure how to add the post-response script to the login request.

'postman' => [
        'enabled' => true,
        'overrides' => [
            // 'info.version' => '2.0.0',
            'info.name' => 'Example API',
            'info.description' => 'API documentation for the Example API.',
            'variables' => [
                [
                    "key"=> "baseUrl",
                    "value"=>"http://xyz_site.test",
                    "type"=>"string"
                ],
                [

                    "key"=>"token",
                    "value"=> null,
                    "type"=>"string"
                ],
                [
                    "key"=>"password",
                    "value"=>"12345678",
                    "type"=>"string"
                ],
                [
                    "key"=>"email_user",
                    "value"=>"customer@example.com",
                    "type"=>"string"
                ]
            ],
            "auth" => [
                "type" => "bearer",
                "bearer" => [
                    "key" => "token",
                    "value" => "{{token}}",
                    "type" => "string"
                ]
            ]
        ],
    ],

Following is the post-response script example snippet from the postman collection export:

{
    "item": [
        {
            "name": "Authentication",
            "item": [
                {
                    "name": "Login User",
                    "event": [
                        {
                            "listen": "test",
                            "script": {
                                "exec": [
                                    "pm.collectionVariables.set(\"token\", pm.response.json().data.token);"
                                ],
                                "type": "text/javascript",
                                "packages": {}
                            }
                        },
                        {
                            "listen": "prerequest",
                            "script": {
                                "exec": [
                                    ""
                                ],
                                "type": "text/javascript",
                                "packages": {}
                            }
                        }
                    ],
                    "request": {
                        "auth": {
                            "type": "noauth"
                        },
                        "method": "POST",
                        "header": [
                            {
                                "key": "Content-Type",
                                "value": "application/json"
                            },
                            {
                                "key": "Accept",
                                "value": "application/json"
                            }
                        ],
                        "body": {
                            "mode": "raw",
                            "raw": "{\"email\":\"{{email_admin}}\",\"password\":\"12345678\"}"
                        },
                        "url": {
                            "raw": "{{baseUrl}}/api/login",
                            "host": [
                                "{{baseUrl}}"
                            ],
                            "path": [
                                "api",
                                "login"
                            ]
                        }
                    },
                    "response": []
                }
            ]
        },
    ]
}

Docs

shalvah commented 1 month ago

I have no idea. Where is the script meant to be specified in the Postman collection file format? Doesn't the overrides section work?