-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Current Behavior
Description:
When using the Admin API to PATCH a route's upstream.nodes field, there is an inconsistency in data type conversion. Currently, the nodes field can be updated from the array format to the hash table format successfully. However, once the nodes field is set to the hash table format, a subsequent PATCH request attempting to change it back to the array format fails, even though both formats are documented as valid in the Admin API.
Expected Behavior
Expected behavior:
Since both nodes formats are documented as valid in the Admin API, the PATCH operation should allow switching between them in both directions, as long as the payload is valid according to the schema.
Actual behavior:
Switching from array to hash table works, but switching from hash table back to array fails with a validation error. This indicates that the schema validator does not permit changing the type of the nodes field during a PATCH operation, despite both types being acceptable for the resource.
Additional context:
The issue likely stems from how PATCH handles partial updates: after the nodes field is stored as a hash table, the validator expects subsequent PATCH requests to also provide a hash table for that field, even though the overall schema allows either type. Because both formats are officially supported, the API should be able to handle type conversions in both directions.
Thank you for looking into this!
Error Logs
No response
Steps to Reproduce
Example formats:
-
Array format (node1):
{ "upstream": { "nodes": [ { "weight": 1, "priority": 0, "host": "127.0.0.1", "port": 80 } ] } } -
Hash table format (node2):
{ "upstream": { "nodes": { "127.0.0.1:8080": 1 } } }
Steps to reproduce:
-
Create a route with the array format (node1) using a
PUTrequest:curl -X PUT http://127.0.0.1:9180/apisix/admin/routes/test \ -H "X-API-KEY: your-api-key" \ -d '{ "uri": "/anything", "upstream": { "nodes": [ { "weight": 1, "priority": 0, "host": "127.0.0.1", "port": 80 } ] } }'
-
Change the route to the hash table format (node2) using a
PATCHrequest:curl -X PATCH http://127.0.0.1:9180/apisix/admin/routes/test \ -H "X-API-KEY: your-api-key" \ -d '{ "upstream": { "nodes": { "127.0.0.1:8080": 1 } } }'
→ This succeeds.
-
Now try to change it back to the array format (node1) using another
PATCHrequest:curl -X PATCH http://127.0.0.1:9180/apisix/admin/routes/test \ -H "X-API-KEY: your-api-key" \ -d '{ "upstream": { "nodes": [ { "weight": 1, "priority": 0, "host": "127.0.0.1", "port": 80 } ] } }'
→ This fails with the following error:
{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"nodes\" validation failed: object matches none of the required"}
Environment
- APISIX version (run
apisix version): - Operating system (run
uname -a): - OpenResty / Nginx version (run
openresty -Vornginx -V): - etcd version, if relevant (run
curl http://127.0.0.1:9090/v1/server_info): - APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run
luarocks --version):
Metadata
Metadata
Assignees
Labels
Type
Projects
Status