fix: accept integer reference ids from the Admin API - #3472
Merged
Merged
Conversation
The gateway's `id_schema` is `anyOf [string, integer]` and it stores the JSON type the writer sent, so a route created by another client with `"plugin_config_id": 10001` reads back with a number in that field. `ResourceRef` called `.trim()` on it and took the whole detail page down to the root error boundary, and before that the resolver refused to save such a resource with "Expected string, received number". Model every reference field with a shared `RefId` that accepts both forms and normalizes to a string, and make `ResourceRef` tolerate the raw value the form holds before validation runs. fix apache#3471, close apache#3470
`PUT /apisix/admin/routes` with `"id": 10001` in the body and no id in the URL stores and returns a numeric primary id, so `ID.id` takes the same `RefId` as the reference fields and the contract test no longer allowlists it. The contract check now walks nested objects as well (`upstream.tls.client_cert_id`, `protocol.superior_id`), the `RefId` unit tests live in `common.test.ts`, and the e2e spec covers a route with a numeric primary id and a stream route.
LiteSun
approved these changes
Sep 1, 2026
guoqqqi
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why submit this pull request?
What changes will this PR take into?
The gateway's
id_schemaisanyOf [string, integer]and it stores the JSON type the writer sent, so a route created by another client with"plugin_config_id": 10001reads back with a number in that field, andPUT /apisix/admin/routeswith"id": 10001in the body stores a numeric primary id. Since #3459,ResourceRefcalls.trim()on that value and every detail page that renders a reference field (routes, stream routes, services, consumers) crashes to "Something went wrong"; before #3459 the page rendered but Save failed with "Expected string, received number".APISIXCommon.RefId(string or positive integer, normalized to a string) and use it for every id-typed field: the resource's ownid,upstream_id,service_id,plugin_config_id,script_id,group_id,client_cert_id,superior_id.ResourceRefreads the id throughtoRefId, so the raw number the form holds before validation no longer throws.protos/detailletszodResolverinfer the form types like the other detail pages do, since the schema now carries a transform.anyOf [string, integer]field, nested ones included, accepts the integer form; unit tests forRefId,IDandtoRefId; an e2e spec that seeds numeric ids through the Admin API and verifies render, resolved link and save for a route (with a numeric primary id), a stream route, a service and a consumer.Related issues
fix #3471, close #3470
Checklist: