diff --git a/pkg/swagger/generator/template_repo.go b/pkg/swagger/generator/template_repo.go index 1274d6b..a7ec658 100644 --- a/pkg/swagger/generator/template_repo.go +++ b/pkg/swagger/generator/template_repo.go @@ -21,6 +21,7 @@ import ( "log" "path" "path/filepath" + "runtime" "strings" "text/template" "text/template/parse" @@ -488,9 +489,17 @@ func padSurround(entry, padWith string, i, ln int) string { return strings.Join(res, ",") } +// padDocument indent multi line document with given pad func padDocument(str string, pad string) string { - // indent multi line document with given pad - lines := strings.Split(str, "\n") + // get the OS name + // set the appropriate line separator + var lineSeparator string + if runtime.GOOS == "windows" { + lineSeparator = "\r\n" + } else { + lineSeparator = "\n" + } + lines := strings.Split(str, lineSeparator) paddingLines := make([]string, 0, len(lines)) for _, line := range lines { paddingLine := line @@ -500,7 +509,7 @@ func padDocument(str string, pad string) string { paddingLines = append(paddingLines, paddingLine) } // no indenting before cascading empty lines - return strings.Join(paddingLines, "\n") + return strings.Join(paddingLines, lineSeparator) } func padComment(str string, pads ...string) string {