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

   ### Current Behavior
   
   With Admin API v3, a list request that uses `page` and `page_size` returns 
`list` as a JSON **object** when the requested page has no items:
   
   ```json
   {"list":{},"total":0}
   ```
   
   This happens both when the resource has no entries at all and when `page` is 
past the last page. Without `page`/`page_size` the same request correctly 
returns `"list":[]`.
   
   Cause: `pagination()` in `apisix/admin/v3_adapter.lua` replaces `body.list` 
with a fresh `table.new(20, 0)`. Unlike the list built in 
`apisix/core/etcd.lua` (`setmetatable({}, array_mt)`), that table has no 
`array_mt`, so cjson encodes it as `{}` when it stays empty.
   
   ### Expected Behavior
   
   `list` is always a JSON array, `[]` when empty, regardless of whether 
pagination parameters are given. Clients written in typed languages (or 
JSON-schema validated) fail on the object form.
   
   ### Error Logs
   
   None.
   
   ### Steps to Reproduce
   
   1. Run APISIX with etcd and `admin_api_version: v3` (default), with no 
routes configured.
   2. `curl "http://127.0.0.1:9180/apisix/admin/routes?page=1&page_size=10"; -H 
"X-API-KEY: $ADMIN_KEY"`
      → `{"list":{},"total":0}`
   3. Compare with `curl "http://127.0.0.1:9180/apisix/admin/routes"; -H 
"X-API-KEY: $ADMIN_KEY"`
      → `{"list":[],"total":0}`
   
   The same applies to any other resource listed through the Admin API 
(upstreams, services, consumers, ...), and to a page beyond the end of a 
non-empty list (e.g. `page=10&page_size=10` with 11 routes).
   
   ### Environment
   
   - APISIX version: master (64d831f)
   - Operating system: not relevant
   - OpenResty / Nginx version: not relevant
   - etcd version: not relevant
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to