test: add a gateway-schema contract test for the zod resource schemas#3449
Open
lxbme wants to merge 1 commit into
Open
test: add a gateway-schema contract test for the zod resource schemas#3449lxbme wants to merge 1 commit into
lxbme wants to merge 1 commit into
Conversation
5 tasks
Contributor
Author
|
Follow-up: the |
lxbme
marked this pull request as ready for review
July 27, 2026 04:00
45 tasks
guoqqqi
approved these changes
Jul 27, 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.
Please answer these questions before submitting a pull request, or your PR will get closed.
Why submit this pull request?
What changes will this PR take into?
This implements the "cheapest structural guard" proposed in the "hand-written zod transcription" item of the frontend review in #3417: a CI test asserting the dashboard's zod resource schemas are looser or equal to APISIX's own schema, so the recurring "form rejects a config the gateway accepts" class (#3146/#3147/#3362/#3376/#3395) can't silently reappear.
How it works
GET /apisix/admin/schema/<resource>.scripts/refresh-gateway-schema.mjs(run viapnpm refresh:gateway-schema) snapshots the 11 resources that expose one — route, service, upstream, consumer, ssl, global_rule, plugin_config, consumer_group, stream_route, proto, credential — intosrc/types/schema/apisix/__fixtures__/gateway/. (secretis omitted: it is schema'd per-manager and the bare endpoint returns 400.) The snapshot is committed and refreshed on APISIX version bumps;_meta.jsonrecords the version (currently 3.17.0).src/types/schema/apisix/gateway-contract.test.tsruns in the unit suite (no gateway needed). For each top-level property the gateway defines it asserts, against the merged dashboard schema: (a) the zod schema knows the field (else the form's resolver silently strips it on submit), and (b) the zod field accepts every value the gateway's enum allows.ALLOWLISTwith a reason — intentional non-support, or a KNOWN GAP flagged for follow-up; never a silent omission. A stale allowlist entry (a field zod now covers) also fails the test, forcing cleanup.What it already caught
Populating the allowlist surfaced one genuine "form too strict" gap, plus several intentional differences:
upstream.schemeomits"kafka": the gateway accepts a kafka-scheme upstream; the dashboard's zod enum does not, so it cannot be created via the form. Allowlisted with a note and flagged for a follow-up fix (which also needs UI support). This is exactly the class the test exists to surface.consumer.id/credential.name(keyed by username / id in the dashboard),proto.{name,labels,desc}(content-only form),consumer_group.name(no separate name field),upstream.{create_time,update_time}(server-managed, not modelled), andstream_route.name(the base read schema omits it, but it is accepted on the write path viaStreamRoutePostSchema, per fix: unify stream-route submit pipelines, drop phantom plugin_config_id #3437).Scope (kept to the "cheapest guard"): top-level properties only — nested objects and plugin configs (which the dashboard passes through, not transcribes) are out of scope, as is required-ness (the full read schema requires server-managed id/timestamps the write path omits, so comparing it produces only false positives). The longer-term JSON-Schema-driven form work (#3347/#3311/#2986) is unaffected.
Related issues
Part of #3417
Checklist:
This is a test + fixtures + a dev script only — no application/runtime code changes — so there is nothing for the e2e suite to exercise. Verified with
tsc, ESLint, and the unit suite (pnpm test, which CI now runs). The test's sensitivity was confirmed by adding a fake property to a fixture (goes red naming the field) and by the stale-allowlist check.