You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/10/18 07:31:04 UTC

[GitHub] [apisix] zhanhengLu opened a new issue, #8111: 使用apisix admin-api创建消费者或路由时,插件中的数组属性被更改为对象属性

zhanhengLu opened a new issue, #8111:
URL: https://github.com/apache/apisix/issues/8111

   ### Description
   
   使用apisix dashborad创建消费者,身份认证选择我们自己开发的插件,插件中有一个属性的格式是数组类型,在这里创建没有问题
   ![image](https://user-images.githubusercontent.com/31837184/196362999-7c29e0e0-e78e-4936-ac2e-99a65542ff0c.png)
   是用apisix dashboard查看也是正常的,如下图:
   ![image](https://user-images.githubusercontent.com/31837184/196363106-00659edb-5cab-4503-a12b-f24296f5fec8.png)
   但是当我用这个参数去直接请求apisix的创建消费者的接口时,产生了问题。
   参照该文档【https://apisix.apache.org/zh/docs/apisix/admin-api/#consumer】调用  PUT	/apisix/admin/consumers这个接口创建资源
   入参为:`{"username":"test_consumer2","plugins":{"sha-zj-plugin":{"app_id":"test","app_key":"test","allow_urls":[],"disable":false}}}`
   接口返回为:```
   {
       "node": {
           "value": {
               "update_time": 1666077788,
               "create_time": 1666077788,
               "plugins": {
                   "sha-zj-plugin": {
                       "app_key": "test",
                       "clock_skew": 0,
                       "disable": false,
                       "encode_uri_params": true,
                       "max_req_body": 524288,
                       **"allow_urls": {
                       },**
                       "app_id": "test",
                       "algorithm": "sha256"
                   }
               },
               "username": "test_consumer2"
           },
           "key": "\/apisix\/consumers\/test_consumer2"
       },
       "action": "set"
   }
   ```
   可以发现,上面加粗字段,这个allow_urls的属性被更改为对象类型
   但是,当我把入参修改为:
   `{"username":"test_consumer3","plugins":{"sha-zj-plugin":{"app_id":"test","app_key":"test","allow_urls":["/all"],"disable":false}}}
   `这个时候的返回却是正确的格式,如下:
   ```
   {
       "node": {
           "value": {
               "update_time": 1666078071,
               "create_time": 1666078071,
               "plugins": {
                   "sha-zj-plugin": {
                       "app_key": "test",
                       "clock_skew": 0,
                       "disable": false,
                       "encode_uri_params": true,
                       "max_req_body": 524288,
                       "allow_urls": [
                           "\/all"
                       ],
                       "app_id": "test",
                       "algorithm": "sha256"
                   }
               },
               "username": "test_consumer3"
           },
           "key": "\/apisix\/consumers\/test_consumer3"
       },
       "action": "set"
   }
   ```
   
   有大佬知道这个问题产生的原因吗?是我的参数需要进行处理嘛?
   
   
   
   
   ### Environment
   
   使用docker部署的apisix,镜像为:apisix:2.12.1-centos
   apisix-dashboard镜像为:apisix-dashboard:2.11-centos
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] monkeyDluffy6017 commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
monkeyDluffy6017 commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1285079568

   APISIX dashboard is written in golang, it will handle the data in etcd directly, and no need to interact with apisix, so it doesn't have the same problem.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] monkeyDluffy6017 commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
monkeyDluffy6017 commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1285079392

   APISIX dashboard is written in golang, it will handle the data in etcd directly, and no need to interact with apisix, so it doesn't have the same problem.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhanhengLu commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
zhanhengLu commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1294358757

   > @zhanhengLu which version of APISIX did you use? we have fix by [#6383](https://github.com/apache/apisix/pull/6383)
   The version I'm using is 2.12, and the way I deploy is using docker, using apache/apisix:2.12.1-alpine.
   
   I see [#6383](https://github.com/apache/apisix/pull/6383). I see this branch merged into the master, but it doesn't seem to have been incorporated into any version, including 3.0.0-beta,[CHANGLOG.md](https://github.com/apache/apisix/blob/release/2.99/CHANGELOG.md#300-beta). I also tried to use the mirror of the latest version, and the empty array still returns an empty object
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhanhengLu commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
zhanhengLu commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1297942410

   thank you ,I'll try it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1294785411

   > I see this branch merged into the master, but it doesn't seem to have been incorporated into any version, including 3.0.0-beta
   
   release since v2.13


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tokers commented on issue #8111: 使用apisix admin-api创建消费者或路由时,插件中的数组属性被更改为对象属性

Posted by GitBox <gi...@apache.org>.
tokers commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1282087951

   I think this is due to lua-cjson decoding the empty array as a Lua table, but encoding it as an empty object. See https://github.com/apache/apisix/issues/4193 to learn if it can help you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhanhengLu closed issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
zhanhengLu closed issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property
URL: https://github.com/apache/apisix/issues/8111


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1286420758

   @zhanhengLu which version of APISIX did you use? we have fix by #6383


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1294823080

   > I also tried to use the mirror of the latest version, and the empty array still returns an empty object
   
   I tested it, no problem.
   
   Modify the schema of example-plugin as follows:
   
   ```lua
   local schema = {
       type = "object",
       properties = {
           i = {type = "number", minimum = 0},
           s = {type = "string"},
           t = {type = "array", minItems = 0},
           ip = {type = "string"},
           port = {type = "integer"},
       },
       required = {"i"},
   }
   ```
   
   `t` is a array and can be empty array.
   
   test:
   
   ```shell
   curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "plugins": {
           "example-plugin": {
               "i": 11,
               "t": []
           }
       },
       "uri": "/server_port"
   }'
   
   ```
   
   I get response as:
   
   ```
   {"key":"\/apisix\/routes\/1","value":{"status":1,"priority":0,"create_time":1666952451,"id":"1","update_time":1666952451,"uri":"\/server_port","plugins":{"example-plugin":{"t":[],"i":11}}}}
   ```
   
   you can see:`"t":[]`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] zhanhengLu commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
zhanhengLu commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1284986009

   
   我看到那个帖子了,说是因为cjson.decode_array_with_array_mt 属性值为FALSE,我翻了下源代码,apisix/core/json.lua,中定义了cjson的属性,如下
   `local cjson = require("cjson.safe")
   local json_encode = cjson.encode
   local clear_tab = require("table.clear")
   local ngx = ngx
   local tostring = tostring
   local type = type
   local pairs = pairs
   local cached_tab = {}
   
   cjson.decode_array_with_array_mt(true)`
   我应该怎么做,能够让apisix接收到空的数组不会改变为空对象?
   
   还有一点我比较好奇,同样的参数,直接调用apisix admin-api会产生这个问题,但是使用apisix-dashboard却没有


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] monkeyDluffy6017 commented on issue #8111: When creating consumer or route using apisix admin-api, array property in plugin is changed to object property

Posted by GitBox <gi...@apache.org>.
monkeyDluffy6017 commented on issue #8111:
URL: https://github.com/apache/apisix/issues/8111#issuecomment-1285073315

   Have you learn about this command: https://github.com/openresty/lua-cjson#decode_array_with_array_mt ?
   It shows the example already.
   ```
   local cjson = require "cjson"
   
   -- default behavior
   local my_json = [[{"my_array":[]}]]
   local t = cjson.decode(my_json)
   cjson.encode(t) -- {"my_array":{}} back to an object
   
   -- now, if this behavior is enabled
   cjson.decode_array_with_array_mt(true)
   
   local my_json = [[{"my_array":[]}]]
   local t = cjson.decode(my_json)
   cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org