Skip to content

Commit

Permalink
Recursively load subdirectory template files (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
shearnd committed Apr 19, 2022
1 parent 344f8e1 commit 9992d0c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/oapi-codegen/oapi-codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ func loadTemplateOverrides(templatesDir string) (map[string]string, error) {
}

for _, f := range files {
// Recursively load subdirectory files, using the path relative to the templates
// directory as the key. This allows for overriding the files in the service-specific
// directories (e.g. echo, chi, etc.).
if f.IsDir() {
subFiles, err := loadTemplateOverrides(path.Join(templatesDir, f.Name()))
if err != nil {
return nil, err
}
for subDir, subFile := range subFiles {
templates[path.Join(f.Name(), subDir)] = subFile
}
continue
}
data, err := ioutil.ReadFile(path.Join(templatesDir, f.Name()))
if err != nil {
return nil, err
Expand Down

0 comments on commit 9992d0c

Please sign in to comment.