Skip to content

Commit

Permalink
make model generation optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vikstrous committed Nov 26, 2019
1 parent d3f6384 commit c2c2d7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
12 changes: 7 additions & 5 deletions api/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (

func Generate(cfg *config.Config, option ...Option) error {
_ = syscall.Unlink(cfg.Exec.Filename)
_ = syscall.Unlink(cfg.Model.Filename)
if cfg.Model.IsDefined() {
_ = syscall.Unlink(cfg.Model.Filename)
}

plugins := []plugin.Plugin{
schemaconfig.New(),
modelgen.New(),
resolvergen.New(),
plugins := []plugin.Plugin{schemaconfig.New()}
if cfg.Model.IsDefined() {
plugins = append(plugins, modelgen.New())
}
plugins = append(plugins, resolvergen.New())

for _, o := range option {
o(cfg, &plugins)
Expand Down
23 changes: 15 additions & 8 deletions codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type Config struct {
SchemaFilename StringList `yaml:"schema,omitempty"`
Exec PackageConfig `yaml:"exec"`
Model PackageConfig `yaml:"model"`
Model PackageConfig `yaml:"model,omitempty"`
Resolver PackageConfig `yaml:"resolver,omitempty"`
AutoBind []string `yaml:"autobind"`
Models TypeMap `yaml:"models,omitempty"`
Expand Down Expand Up @@ -228,8 +228,10 @@ func (c *Config) Check() error {
if err := c.Exec.Check(); err != nil {
return errors.Wrap(err, "config.exec")
}
if err := c.Model.Check(); err != nil {
return errors.Wrap(err, "config.model")
if c.Model.IsDefined() {
if err := c.Model.Check(); err != nil {
return errors.Wrap(err, "config.model")
}
}
if c.Resolver.IsDefined() {
if err := c.Resolver.Check(); err != nil {
Expand All @@ -239,11 +241,14 @@ func (c *Config) Check() error {

// check packages names against conflict, if present in the same dir
// and check filenames for uniqueness
packageConfigList := []PackageConfig{
c.Model,
packageConfigList := []PackageConfig{}
if c.Model.IsDefined() {
packageConfigList = append(packageConfigList, c.Model)
}
packageConfigList = append(packageConfigList, []PackageConfig{
c.Exec,
c.Resolver,
}
}...)
filesMap := make(map[string]bool)
pkgConfigsByDir := make(map[string]PackageConfig)
for _, current := range packageConfigList {
Expand Down Expand Up @@ -364,8 +369,10 @@ func findCfgInDir(dir string) string {
}

func (c *Config) normalize() error {
if err := c.Model.normalize(); err != nil {
return errors.Wrap(err, "model")
if c.Model.IsDefined() {
if err := c.Model.normalize(); err != nil {
return errors.Wrap(err, "model")
}
}

if err := c.Exec.normalize(); err != nil {
Expand Down

0 comments on commit c2c2d7d

Please sign in to comment.