Skip to content

Commit 1d730c5

Browse files
authored
Fix param comment escaping issue (#1890)
This commit fixes a param comment issue where a "\n" gets escaped so it would not be applied to the output swagger file.
1 parent 83fe3ca commit 1d730c5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
281281

282282
requiredText := strings.ToLower(matches[4])
283283
required := requiredText == "true" || requiredText == requiredLabel
284-
description := matches[5]
284+
description := strings.Join(strings.Split(matches[5], "\\n"), "\n")
285285

286286
param := createParameter(paramType, description, name, objectType, refType, required, enums, operation.parser.collectionFormatInQuery)
287287

operation_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,27 @@ func TestParseParamCommentByID(t *testing.T) {
13221322
assert.Equal(t, expected, string(b))
13231323
}
13241324

1325+
func TestParseParamCommentWithMultilineDescriptions(t *testing.T) {
1326+
t.Parallel()
1327+
1328+
comment := `@Param some_id query int true "First line\nSecond line\nThird line"`
1329+
operation := NewOperation(nil)
1330+
err := operation.ParseComment(comment, nil)
1331+
1332+
assert.NoError(t, err)
1333+
b, _ := json.MarshalIndent(operation.Parameters, "", " ")
1334+
expected := `[
1335+
{
1336+
"type": "integer",
1337+
"description": "First line\nSecond line\nThird line",
1338+
"name": "some_id",
1339+
"in": "query",
1340+
"required": true
1341+
}
1342+
]`
1343+
assert.Equal(t, expected, string(b))
1344+
}
1345+
13251346
func TestParseParamCommentByQueryType(t *testing.T) {
13261347
t.Parallel()
13271348

0 commit comments

Comments
 (0)