diff --git a/cmd/gojsonschema/main.go b/cmd/gojsonschema/main.go index 91c77876..4b550341 100644 --- a/cmd/gojsonschema/main.go +++ b/cmd/gojsonschema/main.go @@ -57,7 +57,7 @@ var rootCmd = &cobra.Command{ DefaultOutputName: defaultOutput, DefaultPackageName: defaultPackage, SchemaMappings: []generator.SchemaMapping{}, - ResolveExtensions: append([]string{""}, resolveExtensions...), + ResolveExtensions: resolveExtensions, } for _, id := range allKeys(schemaPackageMap, schemaOutputMap, schemaRootTypeMap) { mapping := generator.SchemaMapping{SchemaID: id} diff --git a/pkg/generator/generate.go b/pkg/generator/generate.go index 6492c545..32bbe51e 100644 --- a/pkg/generator/generate.go +++ b/pkg/generator/generate.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "go/format" + "io" "os" "path/filepath" "reflect" @@ -116,11 +117,12 @@ func (g *Generator) loadSchemaFromFile(fileName, parentFileName string) (*schema fileName = filepath.Join(filepath.Dir(parentFileName), fileName) } - for i, ext := range g.config.ResolveExtensions { + exts := append([]string{""}, g.config.ResolveExtensions...) + for i, ext := range exts { qualified := fileName + ext // Poor man's resolving loop - if i < len(g.config.ResolveExtensions)-1 && !fileExists(qualified) { + if i < len(exts)-1 && !fileExists(qualified) { continue }