Skip to content

Commit

Permalink
fix(convert): Support YAML anchors in plugin options (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored Sep 14, 2023
1 parent e465d0b commit b3c3474
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/config/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func gen(n *yaml.Node) (interface{}, error) {

}

case yaml.AliasNode:
return gen(n.Alias)

default:
return nil, fmt.Errorf("unknown yaml value: %s (%s)", n.Value, n.Tag)

Expand Down
47 changes: 47 additions & 0 deletions internal/config/convert/convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package convert

import (
"testing"

"gopkg.in/yaml.v3"
)

const anchor = `
sql:
- schema: query.sql
queries: query.sql
engine: postgresql
codegen:
- out: gateway/src/gateway/services/organization
plugin: py
options: &base-options
query_parameter_limit: 1
package: gateway
output_models_file_name: null
emit_module: true
emit_generators: false
emit_async: true
- schema: query.sql
queries: query.sql
engine: postgresql
codegen:
- out: gateway/src/gateway/services/project
plugin: py
options: *base-options
`

type config struct {
SQL yaml.Node `yaml:"sql"`
}

func TestAlias(t *testing.T) {
var a config
err := yaml.Unmarshal([]byte(anchor), &a)
if err != nil {
t.Fatal(err)
}
if _, err := gen(&a.SQL); err != nil {
t.Fatal(err)
}
}

0 comments on commit b3c3474

Please sign in to comment.