diff --git a/codegen/config/config.go b/codegen/config/config.go index ba939fcf59a..cfb22b4bf7e 100644 --- a/codegen/config/config.go +++ b/codegen/config/config.go @@ -103,6 +103,16 @@ func LoadConfig(filename string) (*Config, error) { return nil, errors.Wrap(err, "unable to parse config") } + if err := CompleteConfig(config); err != nil { + return nil, err + } + + return config, nil +} + +// CompleteConfig fills in the schema and other values to a config loaded from +// YAML. +func CompleteConfig(config *Config) error { defaultDirectives := map[string]DirectiveConfig{ "skip": {SkipRuntime: true}, "include": {SkipRuntime: true}, @@ -140,12 +150,13 @@ func LoadConfig(filename string) (*Config, error) { return nil }); err != nil { - return nil, errors.Wrapf(err, "failed to walk schema at root %s", pathParts[0]) + return errors.Wrapf(err, "failed to walk schema at root %s", pathParts[0]) } } else { + var err error matches, err = filepath.Glob(f) if err != nil { - return nil, errors.Wrapf(err, "failed to glob schema filename %s", f) + return errors.Wrapf(err, "failed to glob schema filename %s", f) } } @@ -163,13 +174,12 @@ func LoadConfig(filename string) (*Config, error) { var schemaRaw []byte schemaRaw, err = ioutil.ReadFile(filename) if err != nil { - return nil, errors.Wrap(err, "unable to open schema") + return errors.Wrap(err, "unable to open schema") } config.Sources = append(config.Sources, &ast.Source{Name: filename, Input: string(schemaRaw)}) } - - return config, nil + return nil } func (c *Config) Init() error {