Skip to content

Commit

Permalink
Merge pull request #192 from vektah/strict-config
Browse files Browse the repository at this point in the history
Strict config
  • Loading branch information
vektah authored Jul 14, 2018
2 parents 533dcba + a1c02e7 commit f478f81
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codegen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func LoadConfig(filename string) (*Config, error) {
return nil, errors.Wrap(err, "unable to read config")
}

if err := yaml.Unmarshal(b, &config); err != nil {
if err := yaml.UnmarshalStrict(b, &config); err != nil {
return nil, errors.Wrap(err, "unable to parse config")
}

Expand Down
5 changes: 5 additions & 0 deletions codegen/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func TestLoadConfig(t *testing.T) {
_, err := LoadConfig("testdata/cfg/malformedconfig.yml")
require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `asdf` into codegen.Config")
})

t.Run("unknown keys", func(t *testing.T) {
_, err := LoadConfig("testdata/cfg/unknownkeys.yml")
require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 2: field unknown not found in type codegen.Config")
})
}

func TestLoadDefaultConfig(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions codegen/testdata/cfg/unknownkeys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: outer
unknown: foo

0 comments on commit f478f81

Please sign in to comment.