Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a param comment escaping issue where newline characters do not get applied in the output swagger file #1890

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading