Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more validation checks on .yml config file #542

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions codegen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,47 @@ func (cfg *Config) Check() error {
if err := cfg.Resolver.Check(); err != nil {
return errors.Wrap(err, "config.resolver")
}

// check packages names against conflict, if present in the same dir
// and check filenames for uniqueness
packageConfigList := []PackageConfig{
cfg.Model,
cfg.Exec,
cfg.Resolver,
}
filesMap := make(map[string]bool)
pkgConfigsByDir := make(map[string][]PackageConfig)
for i, current := range packageConfigList {
if i == 0 {
Elgarni marked this conversation as resolved.
Show resolved Hide resolved
filesMap[current.Filename] = true
pkgConfigsByDir[current.Dir()] = []PackageConfig{current}
continue
}
_, fileFound := filesMap[current.Filename]
if fileFound {
return fmt.Errorf("filename %s defined more than once", current.Filename)
}
filesMap[current.Filename] = true
prevPkgList, inSameDir := pkgConfigsByDir[current.Dir()]
if inSameDir {
Elgarni marked this conversation as resolved.
Show resolved Hide resolved
for _, previous := range prevPkgList {
if current.Package != previous.Package {
eitherPackageEmpty := previous.Package != "" || current.Package != ""
if eitherPackageEmpty {
if current.Package == filepath.Base(current.Dir()) && previous.Package == "" {
Elgarni marked this conversation as resolved.
Show resolved Hide resolved
break
}
if previous.Package == filepath.Base(previous.Dir()) && current.Package == "" {
break
}
return fmt.Errorf("filenames %s and %s are in the same directory but have different package definitions", current.Filename, previous.Filename)
}
}
}
}
pkgConfigsByDir[current.Dir()] = append(pkgConfigsByDir[current.Dir()], current)
}

return nil
}

Expand Down