dps69208 2018-06-20 11:59
浏览 158
已采纳

swagger php client int []类型/语法错误

I am using a php client generated with swagger codegen 2.3.1. also tried 2.4.0_snapshot, still has the same error. the swagger.json used for generation can be found here

I am trying to use a generated post function that has one parameter of type int[].

according to the generated documentation it should be used like this

$apiInstance = new Swagger\Client\Api\UniverseApi();
$ids = array(new \Swagger\Client\Model\int[]());
$datasource = "tranquility";
$result = $apiInstance->postUniverseNames($ids, $datasource);

if i define $ids like that, it give me a syntax error, unexpected '[', expecting ')'

If I make $ids an array, eg.:

array(2) {
  [0]=>
  int(96305152)
  [1]=>
  int(96075776)
}

it throws an exception:

Exception: Invalid resource type: array.

  • 写回答

2条回答 默认 最新

  • dongshang1979 2018-06-28 16:17
    关注

    Turns out is was a guzzle problem and nothing with the generated client. It's similar to this solution, simply encode the array as json:

    $ids = json_encode(array(new \Swagger\Client\Model\int[]()));
    

    or

    $result = $apiInstance->postUniverseNames(json_encode($ids), $datasource);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?