Skip to content

Commit

Permalink
Fix edge case with resolved extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
atombender committed Mar 12, 2019
1 parent 5408067 commit a818704
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/gojsonschema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 4 additions & 2 deletions pkg/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"go/format"
"io"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a818704

Please sign in to comment.