Skip to content

Commit

Permalink
Fix param comment escaping issue (#1890)
Browse files Browse the repository at this point in the history
This commit fixes a param comment issue where a "\n" gets escaped so it would not be applied to the output swagger file.
  • Loading branch information
yukiomoto authored Sep 20, 2024
1 parent 83fe3ca commit 1d730c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F

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

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

Expand Down
21 changes: 21 additions & 0 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,27 @@ func TestParseParamCommentByID(t *testing.T) {
assert.Equal(t, expected, string(b))
}

func TestParseParamCommentWithMultilineDescriptions(t *testing.T) {
t.Parallel()

comment := `@Param some_id query int true "First line\nSecond line\nThird line"`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)

assert.NoError(t, err)
b, _ := json.MarshalIndent(operation.Parameters, "", " ")
expected := `[
{
"type": "integer",
"description": "First line\nSecond line\nThird line",
"name": "some_id",
"in": "query",
"required": true
}
]`
assert.Equal(t, expected, string(b))
}

func TestParseParamCommentByQueryType(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 1d730c5

Please sign in to comment.