tokers commented on a change in pull request #374:
URL:
https://github.com/apache/apisix-ingress-controller/pull/374#discussion_r613992168
##########
File path: pkg/types/apisix/v1/types.go
##########
@@ -79,16 +79,37 @@ type Metadata struct {
type Route struct {
Metadata `json:",inline" yaml:",inline"`
- Host string `json:"host,omitempty"
yaml:"host,omitempty"`
- Hosts []string `json:"hosts,omitempty"
yaml:"hosts,omitempty"`
- Uri string `json:"uri,omitempty"
yaml:"uri,omitempty"`
- Priority int `json:"priority,omitempty"
yaml:"priority,omitempty"`
- Vars [][]StringOrSlice `json:"vars,omitempty"
yaml:"vars,omitempty"`
- Uris []string `json:"uris,omitempty"
yaml:"uris,omitempty"`
- Methods []string `json:"methods,omitempty"
yaml:"methods,omitempty"`
- RemoteAddrs []string `json:"remote_addrs,omitempty"
yaml:"remote_addrs,omitempty"`
- UpstreamId string `json:"upstream_id,omitempty"
yaml:"upstream_id,omitempty"`
- Plugins Plugins `json:"plugins,omitempty"
yaml:"plugins,omitempty"`
+ Host string `json:"host,omitempty" yaml:"host,omitempty"`
+ Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
+ Uri string `json:"uri,omitempty" yaml:"uri,omitempty"`
+ Priority int `json:"priority,omitempty"
yaml:"priority,omitempty"`
+ Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
+ Uris []string `json:"uris,omitempty" yaml:"uris,omitempty"`
+ Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
+ RemoteAddrs []string `json:"remote_addrs,omitempty"
yaml:"remote_addrs,omitempty"`
+ UpstreamId string `json:"upstream_id,omitempty"
yaml:"upstream_id,omitempty"`
+ Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
+}
+
Review comment:
Add a comment for it.
```suggestion
// Vars represents the route match expressions of APISIX.
type Vars [][]StringOrSlice
```
##########
File path: pkg/apisix/resource_test.go
##########
@@ -74,3 +75,18 @@ func TestItemConvertRoute(t *testing.T) {
assert.Equal(t, r.Methods[1], "POST")
assert.Equal(t, r.Name, "unknown")
}
+
+func TestRouteVarsUnmarshalJSONCompatibility(t *testing.T) {
+ var route v1.Route
+ data := `{"vars":{}}`
+ err := json.Unmarshal([]byte(data), &route)
+ assert.Nil(t, err)
+
+ data = `{"vars":{"a":"b"}}`
+ err = json.Unmarshal([]byte(data), &route)
+ assert.Equal(t, err.Error(), "unexpected non-empty object")
+
+ data = `{"vars":[]}`
+ err = json.Unmarshal([]byte(data), &route)
+ assert.Nil(t, err)
Review comment:
Also add a normal case where `vars` is a non-empty slice.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]