Skip to content

Commit de34b88

Browse files
authored
fix: create directories if they do not exist before writing output file (oapi-codegen#1994)
As noted in oapi-codegen#1052, if the parent directory of the output file doesn't exist, it will be automatically created before writing the generated code. This prevents errors if the specified output path contains a non-existent directory. Closes oapi-codegen#1052.
1 parent f2bf249 commit de34b88

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

cmd/oapi-codegen/oapi-codegen.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ func main() {
319319
}
320320

321321
if opts.OutputFile != "" {
322+
if err := os.MkdirAll(filepath.Dir(opts.OutputFile), 0o755); err != nil {
323+
errExit("error unable to create directory: %s\n", err)
324+
}
322325
err = os.WriteFile(opts.OutputFile, []byte(code), 0o644)
323326
if err != nil {
324327
errExit("error writing generated code to file: %s\n", err)

0 commit comments

Comments
 (0)