guzzle / guzzle-services

Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.
MIT License
253 stars 78 forks source link

Operations extends is broken in 1.1.1 #145

Closed delamart closed 7 years ago

delamart commented 7 years ago

I just upgraded to version 1.1.1 and my unit tests stopped working because a parameter is no longer being set in my commands. Version 1.1.0 works fine.

I used the extends option like this:

<?php
        $ops['abstract_json_operation' => [
                'httpMethod' => 'POST',
                'responseModel' => 'result',
                'parameters' => [
                    'format' => [
                        'type' => 'string',
                        'default' => 'json',
                        'location' => 'formParam',
                    ],
                ],
            ],
            'checkAccount'] => [
                'extends' => 'abstract_json_operation',
                'uri' => '/api/checkAccount',
                'parameters' => [
                    'username' => [
                        'required' => true,
                        'type' => 'string',
                        'location' => 'formParam',
                    ],
                ]
            ]
        ];

The parameter format=json was being set correctly on all commands but now I have to set it manually in the command if I want it to work.

Konafets commented 7 years ago

Can you post your faling test?

delamart commented 7 years ago

Sorry can't post my code as is, and technically my unit tests are more integration tests as I connect to a live API (test server).

Basically I have the above operations and use the following model:

$models['result' => [
                'type' => 'object',
                'additionalProperties' => [
                    'location' => 'json'
                ]
        ]
];

I use a \GuzzleHttp\Client with a custom Handler to set HTTP Basic Auth on every request and a GuzzleHttp\Command\Guzzle\GuzzleClient with the above operations and models as GuzzleHttp\Command\Guzzle\Description.

And when I do $guzzle_client-> checkAccount(['username' => 'user']) the format parameter is set in version 1.1.0 and I get the expected result from my api. But in version 1.1.1, I need to do $guzzle_client-> checkAccount(['username' => 'user', 'format' => 'json']) to get the expected response from my API.

If I have some time I can try and provide some simple test code to reproduce this. The issue could still be linked to my external API but since the behavior clearly changes between the two versions I kind of doubt it.

delamart commented 7 years ago

Ok I had time to write a quick test. I forked the project and added a test which works with tag 1.1.0 but no longer in master.

See commit here: https://github.com/delamart/guzzle-services/commit/2d50fa4fb9f6ac4f65a6271f7d7079be91b396aa

Konafets commented 7 years ago

@delamart Thanks for your test. This helped to find the culprit.

delamart commented 7 years ago

Great, thanks I upgraded to 1.1.2 and my lib works again.