diff --git a/cmd/oapi-gen/gen.go b/cmd/oapi-gen/gen.go index e4e1447..d551255 100644 --- a/cmd/oapi-gen/gen.go +++ b/cmd/oapi-gen/gen.go @@ -264,7 +264,8 @@ func docToString(cg *ast.CommentGroup) string { return "" } - s = strings.Join(strings.Split(s, "\n"), " ") + s = strings.TrimSuffix(s, "\n") + s = strings.Join(strings.Split(s, "\n"), "\\n") // Escape newlines. return strings.TrimSpace(s) } diff --git a/cmd/oapi-gen/testdata/all.go b/cmd/oapi-gen/testdata/all.go index c26cfd3..77f5a0c 100644 --- a/cmd/oapi-gen/testdata/all.go +++ b/cmd/oapi-gen/testdata/all.go @@ -6,7 +6,7 @@ package testdata func (TestObject) Docs() map[string]string { return map[string]string{ "B": "B is another example field.", - "a": "A is an example field with "quotes".", + "a": "A is an example field with "quotes"\nand a newline.", } } diff --git a/cmd/oapi-gen/testdata/not-all.go b/cmd/oapi-gen/testdata/not-all.go index e95e1c5..431e22e 100644 --- a/cmd/oapi-gen/testdata/not-all.go +++ b/cmd/oapi-gen/testdata/not-all.go @@ -6,7 +6,7 @@ package testdata func (TestObject) Docs() map[string]string { return map[string]string{ "B": "B is another example field.", - "a": "A is an example field with "quotes".", + "a": "A is an example field with "quotes"\nand a newline.", } } diff --git a/cmd/oapi-gen/testdata/test.go b/cmd/oapi-gen/testdata/test.go index 4c14c51..31f1173 100644 --- a/cmd/oapi-gen/testdata/test.go +++ b/cmd/oapi-gen/testdata/test.go @@ -4,7 +4,8 @@ package testdata // //openapi:gen type TestObject struct { - // A is an example field with "quotes". + // A is an example field with "quotes" + // and a newline. A string `json:"a"` // B is another example field. diff --git a/gen_test.go b/gen_test.go index 23b4c11..624d079 100644 --- a/gen_test.go +++ b/gen_test.go @@ -185,7 +185,7 @@ type TestObject struct { func (TestObject) Docs() map[string]string { return map[string]string{ - "test1": "Some test docs", + "test1": "Test1 is an documented field with "quotes"\nand a newline.", } } diff --git a/testdata/spec-pkgseg0.json b/testdata/spec-pkgseg0.json index 942e34e..36bef23 100644 --- a/testdata/spec-pkgseg0.json +++ b/testdata/spec-pkgseg0.json @@ -26,7 +26,7 @@ }, "properties": { "test1": { - "description": "Some test docs", + "description": "Test1 is an documented field with \u0026#34;quotes\u0026#34;\nand a newline.", "type": "string" }, "test2": { diff --git a/testdata/spec.json b/testdata/spec.json index 741cea5..4a61ca1 100644 --- a/testdata/spec.json +++ b/testdata/spec.json @@ -26,7 +26,7 @@ }, "properties": { "test1": { - "description": "Some test docs", + "description": "Test1 is an documented field with \u0026#34;quotes\u0026#34;\nand a newline.", "type": "string" }, "test2": {