Skip to content

Commit

Permalink
enhancement: remove backticks from struct field's comment (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubogdan authored and easonlin404 committed Jul 10, 2019
1 parent be6d0b2 commit 288d21c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,10 @@ func (parser *Parser) parseStruct(pkgName string, field *ast.Field) (map[string]
}
var desc string
if field.Doc != nil {
desc = strings.TrimSpace(field.Doc.Text())
desc = strings.TrimSpace(strings.Replace(field.Doc.Text(), "`", "", -1))
}
if desc == "" && field.Comment != nil {
desc = strings.TrimSpace(field.Comment.Text())
desc = strings.TrimSpace(strings.Replace(field.Comment.Text(), "`", "", -1))
}
// TODO: find package of schemaType and/or arrayType

Expand Down
8 changes: 8 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,14 @@ func TestParseStructComment(t *testing.T) {
"error": {
"description": "Error an Api error",
"type": "string"
},
"errorCtx": {
"description": "Error context tick comment",
"type": "string"
},
"errorNo": {
"description": "Error number tick comment",
"type": "integer"
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion testdata/struct_comment/web/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type Post struct {

type APIError struct {
// Error an Api error
Error string // Error this is Line comment
Error string // Error this is Line comment
// Error `number` tick comment
ErrorNo int64
ErrorCtx string // Error `context` tick comment
CreatedAt time.Time // Error time
}

0 comments on commit 288d21c

Please sign in to comment.