Skip to content

Commit b3c3474

Browse files
authored
fix(convert): Support YAML anchors in plugin options (#2733)
1 parent e465d0b commit b3c3474

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

internal/config/convert/convert.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func gen(n *yaml.Node) (interface{}, error) {
5959

6060
}
6161

62+
case yaml.AliasNode:
63+
return gen(n.Alias)
64+
6265
default:
6366
return nil, fmt.Errorf("unknown yaml value: %s (%s)", n.Value, n.Tag)
6467

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package convert
2+
3+
import (
4+
"testing"
5+
6+
"gopkg.in/yaml.v3"
7+
)
8+
9+
const anchor = `
10+
sql:
11+
- schema: query.sql
12+
queries: query.sql
13+
engine: postgresql
14+
codegen:
15+
- out: gateway/src/gateway/services/organization
16+
plugin: py
17+
options: &base-options
18+
query_parameter_limit: 1
19+
package: gateway
20+
output_models_file_name: null
21+
emit_module: true
22+
emit_generators: false
23+
emit_async: true
24+
25+
- schema: query.sql
26+
queries: query.sql
27+
engine: postgresql
28+
codegen:
29+
- out: gateway/src/gateway/services/project
30+
plugin: py
31+
options: *base-options
32+
`
33+
34+
type config struct {
35+
SQL yaml.Node `yaml:"sql"`
36+
}
37+
38+
func TestAlias(t *testing.T) {
39+
var a config
40+
err := yaml.Unmarshal([]byte(anchor), &a)
41+
if err != nil {
42+
t.Fatal(err)
43+
}
44+
if _, err := gen(&a.SQL); err != nil {
45+
t.Fatal(err)
46+
}
47+
}

0 commit comments

Comments
 (0)