Skip to content

Commit

Permalink
feat: support line-comments to struct comment (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpig authored and easonlin404 committed Mar 26, 2019
1 parent 92f098d commit e4ec0fe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,9 @@ type Account struct {
```go
type Account struct {
// ID this is userid
ID int `json:"id"
// ID this is userid
ID int `json:"id"`
Name string `json:"name"` // This is Name
}
```
Expand Down
3 changes: 3 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@ func (parser *Parser) parseStruct(pkgName string, field *ast.Field) (map[string]
if field.Doc != nil {
desc = strings.TrimSpace(field.Doc.Text())
}
if desc == "" && field.Comment != nil {
desc = strings.TrimSpace(field.Comment.Text())
}
// TODO: find package of schemaType and/or arrayType

if structField.crossPkg != "" {
Expand Down
1 change: 1 addition & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,7 @@ func TestParseStructComment(t *testing.T) {
"type": "object",
"properties": {
"createdAt": {
"description": "Error time",
"type": "string"
},
"error": {
Expand Down
4 changes: 2 additions & 2 deletions testdata/struct_comment/web/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ type Post struct {

type APIError struct {
// Error an Api error
Error string
CreatedAt time.Time
Error string // Error this is Line comment
CreatedAt time.Time // Error time
}

0 comments on commit e4ec0fe

Please sign in to comment.