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

Creating an array parameter fails #35

Open
nullproxy opened this issue Jul 1, 2017 · 6 comments
Open

Creating an array parameter fails #35

nullproxy opened this issue Jul 1, 2017 · 6 comments

Comments

@nullproxy
Copy link
Contributor

When defining a parameter as an array using Request::newParam() I got an error stating that the data type must be a string, yet I'm defining an array in PHP.

In my case, I'm defining an array where each item is an array, for example:

$param = $request->newParam('params', [['a', 'b', 'c'], ['d', 'e', 'f']], 'array');

Here is the error message received:

Callback error: Language error (shutdown) (1) Uncaught TypeError: Argument 2 passed to Katana\Sdk\Api\ServiceCall::newParam() must be of the type string, array given, called in /vendor/kusanagi/katana-sdk-php7/src/Api/RequestApi.php on line 270 and defined in /vendor/kusanagi/katana-sdk-php7/src/Api/ParamAccessorTrait.php:74
Stack trace:
#0 /vendor/kusanagi/katana-sdk-php7/src/Api/RequestApi.php(270): Katana\Sdk\Api\ServiceCall->newParam('params', Array, 'array')
#1 /middleware.php(45): Katana\Sdk\Api\RequestApi->newParam('params', Array, 'array')
#2 /vendor/kusanagi/katana-sdk-php7/src/Executor/AbstractExecutor.php(77): {closure}(Object(Katana\Sdk\Api\RequestApi))
#3 /vendor/kusanagi/katana-sdk-php7/src/Executor/ZeroMqLoopExecutor.php(138): 

The issue appears to come from here:

https://github.com/kusanagi/katana-sdk-php7/blob/master/src/Api/ParamAccessorTrait.php#L76

This was using version 1.1.4 of the framework, with system info below:

Linux work 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
@fcastilloes
Copy link
Contributor

That was fixed for 1.0.5: 83a4692

Can you double check your SDK version?

@nullproxy
Copy link
Contributor Author

The required dependency is "kusanagi/katana-sdk-php7", with the version constraint set as "^1.1".

When running composer show it gives the following:

kusanagi/katana-sdk-php7 1.1.x-dev f098bc2

Which corresponds the the latest commit on the 1.1 branch.

@fcastilloes
Copy link
Contributor

Version branches was not being updated. Merged now.

@nullproxy nullproxy reopened this Jul 2, 2017
@nullproxy
Copy link
Contributor Author

I now get the following:

Invalid parameter for action "call" on Service "proxy" (1.0.0): "params"

The configuration for the param is the following:

<param name="params" type="array" required="true"/>

And the definition of the Param is as defined before:

$param = $request->newParam('params', [['a', 'b', 'c'], ['d', 'e', 'f']], 'array');

@jeronimoalbi
Copy link
Member

jeronimoalbi commented Jul 8, 2017

@nullproxy can you try adding array-format="multi" to the param definition. By default array-format is "csv" and you are sending a "multi" array.

@fcastilloes
Copy link
Contributor

I've done a couple tests with an array param set from the request middleware and I think the issue is in the framework, not in the SDK.

I got an action with this config (removing the irrelevant for brevity):

action:
  - name: list
    param:
      - name: ids
        type: array
        http-gateway: false

Then I did a test with a simple array and logging both the message sent to the framework and the result from the SDK:

$param = $request->newParam('ids', ['a', 'b', 'c'], 'array');

The message looks correct.

{
  "cr": {
    "n": "rest",
    "r": {
      "c": {
        "s": "orgs",
        "v": "1.1.0-qa.5",
        "a": "list",
        "p": [
          {
            "n": "ids",
            "v": [
              "a",
              "b",
              "c"
            ],
            "t": "array"
          }
        ]
      }
    }
  }
}

But the log does not match:

2017-08-31T17:58:43.919Z [DEBUG] [SDK] ["a"]

Then repeated the test with a multi array, with this other code:

$param = $request->newParam('ids', [['a', 'b', 'c'], ['d', 'e', 'f']], 'array');

Once again, the message looks good.

{
  "cr": {
    "n": "rest",
    "r": {
      "c": {
        "s": "orgs",
        "v": "1.1.0-qa.5",
        "a": "list",
        "p": [
          {
            "n": "ids",
            "v": [
              [
                "a",
                "b",
                "c"
              ],
              [
                "d",
                "e",
                "f"
              ]
            ],
            "t": "array"
          }
        ]
      }
    }
  }
}

But now I get the same error mentioned in the comment above.

Invalid parameter for action "list" on Service "orgs" (1.1.0-qa.5): "ids"

Then, trying with array-multi as suggested @jeronimoalbi solves both tests.

2017-08-31T18:09:41.727Z [DEBUG] [SDK] [["a","b","c"],["d","e","f"]]
2017-08-31T18:10:40.136Z [DEBUG] [SDK] ["a","b","c"]

I think there might be something wrong with the arrays in the framework here, but I can see no issue in the SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants