This is an automated email from the ASF dual-hosted git repository. AlinsRan pushed a commit to branch fix/httproute-regex-uris-null in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
commit dc691f793c0acc4a3dedb526deba26cb18eeed89 Author: rongxin <[email protected]> AuthorDate: Tue May 26 10:28:53 2026 +0800 fix: omit uris field when HTTPRoute path type is RegularExpression When path.type is RegularExpression, the controller sets route.Vars for regex matching but leaves route.Uris as nil. The Uris field lacked omitempty, causing it to serialize as "uris": null in the JSON payload. APISIX Admin API v3 strictly requires uris to be an array, so it rejects the entire bulk ADC sync payload with HTTP 400, breaking ALL routes in the cluster, not just the offending one. Add omitempty to the Uris JSON/YAML tag so the field is omitted when nil. Add a unit test to verify that RegularExpression path matches produce no Uris and the correct Vars entry. Fixes #2764 Co-authored-by: Copilot <[email protected]> --- api/adc/types.go | 2 +- internal/adc/translator/httproute_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/adc/types.go b/api/adc/types.go index 130d63d0..0683c77f 100644 --- a/api/adc/types.go +++ b/api/adc/types.go @@ -135,7 +135,7 @@ type Route struct { Priority *int64 `json:"priority,omitempty" yaml:"priority,omitempty"` RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"` Timeout *Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"` - Uris []string `json:"uris" yaml:"uris"` + Uris []string `json:"uris,omitempty" yaml:"uris,omitempty"` Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"` } diff --git a/internal/adc/translator/httproute_test.go b/internal/adc/translator/httproute_test.go index 7b11e129..45079052 100644 --- a/internal/adc/translator/httproute_test.go +++ b/internal/adc/translator/httproute_test.go @@ -309,3 +309,28 @@ func TestAttachBackendTrafficPolicyHealthCheck(t *testing.T) { }) } } + +func TestTranslateGatewayHTTPRouteMatchRegexPath(t *testing.T) { + pathType := gatewayv1.PathMatchRegularExpression + pathValue := "/lk.*" + + match := &gatewayv1.HTTPRouteMatch{ + Path: &gatewayv1.HTTPPathMatch{ + Type: &pathType, + Value: &pathValue, + }, + } + + translator := &Translator{Log: logr.Discard()} + route, err := translator.translateGatewayHTTPRouteMatch(match) + require.NoError(t, err) + + // Uris must be nil (omitted) when path type is RegularExpression, + // so that the JSON payload does not contain "uris: null" which is + // rejected by APISIX Admin API v3. + assert.Nil(t, route.Uris, "Uris should be nil for RegularExpression path type") + assert.Len(t, route.Vars, 1) + assert.Equal(t, adctypes.StringOrSlice{StrVal: "uri"}, route.Vars[0][0]) + assert.Equal(t, adctypes.StringOrSlice{StrVal: "~~"}, route.Vars[0][1]) + assert.Equal(t, adctypes.StringOrSlice{StrVal: pathValue}, route.Vars[0][2]) +}
