diff --git a/pkg/file/codegen/main.go b/pkg/file/codegen/main.go index 62b2ae1..85f80ba 100644 --- a/pkg/file/codegen/main.go +++ b/pkg/file/codegen/main.go @@ -76,14 +76,7 @@ func main() { }, } - schema.Definitions["FFilterChain"].AnyOf = []*jsonschema.Type{ - { - Required: []string{"filters", "name"}, - }, - { - Required: []string{"filters", "id"}, - }, - } + schema.Definitions["FFilterChain"].Required = []string{"filters"} schema.Definitions["FFilterChain"].Properties["enabled"] = &jsonschema.Type{ Type: "boolean", diff --git a/pkg/file/kong_json_schema.json b/pkg/file/kong_json_schema.json index d5cda3c..c68dfb0 100644 --- a/pkg/file/kong_json_schema.json +++ b/pkg/file/kong_json_schema.json @@ -618,6 +618,9 @@ "type": "object" }, "FFilterChain": { + "required": [ + "filters" + ], "properties": { "created_at": { "type": "integer" @@ -654,21 +657,7 @@ } }, "additionalProperties": false, - "type": "object", - "anyOf": [ - { - "required": [ - "filters", - "name" - ] - }, - { - "required": [ - "filters", - "id" - ] - } - ] + "type": "object" }, "FLicense": { "properties": { diff --git a/pkg/file/readfile_test.go b/pkg/file/readfile_test.go index 835ef5e..45f98a5 100644 --- a/pkg/file/readfile_test.go +++ b/pkg/file/readfile_test.go @@ -364,6 +364,57 @@ kong.log.set_serialize_value("span_id", parse_traceid(ngx.ctx.KONG_SPANS[1].span }, }, }, + { + Service: kong.Service{ + Name: kong.String("service-with-filter-chain"), + Host: kong.String("test"), + }, + Routes: []*FRoute{ + { + Route: kong.Route{ + Name: kong.String("route-with-filter-chain"), + Hosts: kong.StringSlice("test"), + Protocols: kong.StringSlice("http"), + }, + FilterChains: []*FFilterChain{ + { + FilterChain: kong.FilterChain{ + Filters: []*kong.Filter{ + { + Name: kong.String("filter-1"), + Config: kong.JSONRawMessage(`{"add":{"headers":["x-foo:123456"]}}`), + }, + { + Name: kong.String("filter-2"), + Config: kong.JSONRawMessage(`"my config"`), + }, + { + Name: kong.String("filter-3"), + }, + }, + }, + }, + }, + }, + }, + FilterChains: []*FFilterChain{ + { + FilterChain: kong.FilterChain{ + Filters: []*kong.Filter{ + { + Name: kong.String("filter-1"), + Config: kong.JSONRawMessage(`{"add":{"headers":["x-foo:123456"]}}`), + }, + { + Name: kong.String("filter-2"), + Config: kong.JSONRawMessage(`"{\n \"test\": 123\n}\n"`), + Enabled: kong.Bool(true), + }, + }, + }, + }, + }, + }, }, Consumers: []FConsumer{ { diff --git a/pkg/file/testdata/valid/filter-chains.yaml b/pkg/file/testdata/valid/filter-chains.yaml new file mode 100644 index 0000000..c5c1f0d --- /dev/null +++ b/pkg/file/testdata/valid/filter-chains.yaml @@ -0,0 +1,32 @@ +services: +- name: service-with-filter-chain + host: test + routes: + - hosts: + - test + name: route-with-filter-chain + protocols: + - http + filter_chains: + - filters: + - config: + add: + headers: + - x-foo:123456 + name: filter-1 + - config: my config + name: filter-2 + - name: filter-3 + filter_chains: + - filters: + - config: + add: + headers: + - x-foo:123456 + name: filter-1 + - config: | + { + "test": 123 + } + enabled: true + name: filter-2