Skip to content

Commit

Permalink
fix: do not require name/id for filter-chain entities (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh authored Jun 13, 2024
1 parent 2947f60 commit ac65306
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 23 deletions.
9 changes: 1 addition & 8 deletions pkg/file/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 4 additions & 15 deletions pkg/file/kong_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@
"type": "object"
},
"FFilterChain": {
"required": [
"filters"
],
"properties": {
"created_at": {
"type": "integer"
Expand Down Expand Up @@ -654,21 +657,7 @@
}
},
"additionalProperties": false,
"type": "object",
"anyOf": [
{
"required": [
"filters",
"name"
]
},
{
"required": [
"filters",
"id"
]
}
]
"type": "object"
},
"FLicense": {
"properties": {
Expand Down
51 changes: 51 additions & 0 deletions pkg/file/readfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
32 changes: 32 additions & 0 deletions pkg/file/testdata/valid/filter-chains.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ac65306

Please sign in to comment.