@@ -37,8 +37,9 @@ var templates embed.FS
3737// globalState stores all global state. Please don't put global state anywhere
3838// else so that we can easily track it.
3939var globalState struct {
40- options Configuration
41- spec * openapi3.T
40+ options Configuration
41+ spec * openapi3.T
42+ importMapping importMap
4243}
4344
4445// goImport represents a go package to be imported in the generated code
@@ -67,8 +68,6 @@ func (im importMap) GoImports() []string {
6768 return goImports
6869}
6970
70- var importMapping importMap
71-
7271func constructImportMapping (importMapping map [string ]string ) importMap {
7372 var (
7473 pathToName = map [string ]string {}
@@ -101,8 +100,7 @@ func Generate(spec *openapi3.T, opts Configuration) (string, error) {
101100 // This is global state
102101 globalState .options = opts
103102 globalState .spec = spec
104-
105- importMapping = constructImportMapping (opts .ImportMapping )
103+ globalState .importMapping = constructImportMapping (opts .ImportMapping )
106104
107105 filterOperationsByTag (spec , opts )
108106 if ! opts .OutputOptions .SkipPrune {
@@ -237,7 +235,7 @@ func Generate(spec *openapi3.T, opts Configuration) (string, error) {
237235
238236 var inlinedSpec string
239237 if opts .Generate .EmbeddedSpec {
240- inlinedSpec , err = GenerateInlinedSpec (t , importMapping , spec )
238+ inlinedSpec , err = GenerateInlinedSpec (t , globalState . importMapping , spec )
241239 if err != nil {
242240 return "" , fmt .Errorf ("error generating Go handlers for Paths: %w" , err )
243241 }
@@ -246,7 +244,7 @@ func Generate(spec *openapi3.T, opts Configuration) (string, error) {
246244 var buf bytes.Buffer
247245 w := bufio .NewWriter (& buf )
248246
249- externalImports := append (importMapping .GoImports (), importMap (xGoTypeImports ).GoImports ()... )
247+ externalImports := append (globalState . importMapping .GoImports (), importMap (xGoTypeImports ).GoImports ()... )
250248 importsOut , err := GenerateImports (t , externalImports , opts .PackageName )
251249 if err != nil {
252250 return "" , fmt .Errorf ("error generating imports: %w" , err )
0 commit comments