diff --git a/encoding/gocode/gen.go b/encoding/gocode/gen.go index 823a91e..2a68774 100644 --- a/encoding/gocode/gen.go +++ b/encoding/gocode/gen.go @@ -123,10 +123,10 @@ func GenerateTypesOpenAPI(sch thema.Schema, cfg *TypeConfigOpenAPI) ([]byte, err } return PostprocessGoFile(GenGoFile{ - Path: fmt.Sprintf("%s_type_gen.go", sch.Lineage().Name()), - Appliers: applyFuncs, - In: []byte(gostr), - ErrIfAdd: !cfg.IgnoreDiscoveredImports, + Path: fmt.Sprintf("%s_type_gen.go", sch.Lineage().Name()), + Appliers: applyFuncs, + In: []byte(gostr), + IgnoreDiscoveredImports: !cfg.IgnoreDiscoveredImports, }) } @@ -343,10 +343,10 @@ func GenerateLineageBinding(lin thema.Lineage, cfg *BindingConfig) ([]byte, erro } return PostprocessGoFile(GenGoFile{ - Path: fmt.Sprintf("%s_binding_gen.go", strings.ToLower(lin.Name())), - Appliers: cfg.ApplyFuncs, - In: buf.Bytes(), - ErrIfAdd: !cfg.IgnoreDiscoveredImports, + Path: fmt.Sprintf("%s_binding_gen.go", strings.ToLower(lin.Name())), + Appliers: cfg.ApplyFuncs, + In: buf.Bytes(), + IgnoreDiscoveredImports: !cfg.IgnoreDiscoveredImports, }) } diff --git a/encoding/gocode/postprocessing.go b/encoding/gocode/postprocessing.go index 49fc6a2..acfa365 100644 --- a/encoding/gocode/postprocessing.go +++ b/encoding/gocode/postprocessing.go @@ -16,10 +16,10 @@ import ( ) type GenGoFile struct { - ErrIfAdd bool - Path string - Appliers []dstutil.ApplyFunc - In []byte + Path string + Appliers []dstutil.ApplyFunc + In []byte + IgnoreDiscoveredImports bool } func PostprocessGoFile(cfg GenGoFile) ([]byte, error) { @@ -45,7 +45,7 @@ func PostprocessGoFile(cfg GenGoFile) ([]byte, error) { return nil, fmt.Errorf("goimports processing of generated file failed: %w", err) } - if cfg.ErrIfAdd { + if !cfg.IgnoreDiscoveredImports { // Compare imports before and after; warn about performance if some were added gfa, _ := parser.ParseFile(fset, fname, string(byt), parser.ParseComments) imap := make(map[string]bool)