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

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条)

报告相同问题?

悬赏问题

  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频