Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in array parameter serialization #128

Closed
bakura10 opened this issue Jan 9, 2017 · 3 comments
Closed

Regression in array parameter serialization #128

bakura10 opened this issue Jan 9, 2017 · 3 comments
Assignees
Labels
Milestone

Comments

@bakura10
Copy link
Contributor

bakura10 commented Jan 9, 2017

Hi :),

First of all thanks a lot for the hard work that has been achieved in the new Guzzle services.

I've found a regression compared to my previous Guzzle 3 based service descriptor and I'm unsure how to fix it.

In one of my command, I have this:

'GetMetafields' => [
            'httpMethod'       => 'GET',
            'uri'              => 'admin/metafields.json',
            'responseModel'    => 'GenericModel',
            'parameters'       => [
                'metafield' => [
                    'description' => 'accepts sub-fields "owner_id" and "owner_resource"',
                    'location'    => 'query',
                    'type'        => 'array',
                    'required'    => false
                ]
            ]
        ],

Previously, doing this:

$client->getMetafields(['metafield' => ['owner_id' => 'bar', 'owner_resource' => 'baz']]);

would properly serialize this code to the GET query "admin/metafields?metafield[owner_id]=bar&metafield[owner_resource]=baz".

However, since upgrading to Guzzle 6, it serializes to "admin/metafields?metafield=bar&metafield=baz", which is obviously wrong.

I've also tried the "object" type instead of array, and I also tried to add "additionalProperties" to true for the parameter, without any luck.

What is the correct way to fix this issue in Guzzle 6?

@bakura10 bakura10 changed the title Regression in array parameters Regression in array parameter serialization Jan 9, 2017
@bakura10
Copy link
Contributor Author

Actually, I think the proper type should be "object" instead of array for this use case.

However, after more testing, the "array" type still behaves strange. For instance, if I set a type of array and use this:

$client->getMetafields(['metafield' => [1, 2])

The client serialize it this way: "admin/metafields?metafield=1&metafield=2", while it should be "admin/metafields[]=1&metafields[]=2".

I'm going to see if I can find a reason why it's behaving this way.

@bakura10
Copy link
Contributor Author

After investigation it appears the issue lies here: https://github.com/guzzle/psr7/blob/master/src/functions.php#L571

As stated in the function, "This function can use the return value of parse_query() to build a query string. This function does not modify the provided keys when an array is encountered (like http_build_query would)."

This is actually a major issue here, as we do not have any control to override this in the service client. It makes usage of array and object basically impossible :/.

@jeremeamia @Konafets would you have an idea of why this is happening thsi way? :/

@Konafets
Copy link
Contributor

Fixed in 7846618

@Konafets Konafets added the bug label Jan 13, 2017
@Konafets Konafets added this to the 1.0.1 milestone Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants