Skip to content

Commit

Permalink
Merge pull request #94 from evilnoxx/main
Browse files Browse the repository at this point in the history
Use inline comment if no other comment is available
  • Loading branch information
samlown authored Sep 28, 2023
2 parents d8087c4 + 2b4f560 commit 2bf120d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions comment_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func ExtractGoComments(base, path string, commentMap map[string]string) error {
}
case *ast.Field:
txt := x.Doc.Text()
if txt == "" {
txt = x.Comment.Text()
}
if typ != "" && txt != "" {
for _, n := range x.Names {
if ast.IsExported(n.String()) {
Expand Down
4 changes: 3 additions & 1 deletion examples/nested/nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type (
// Plant represents the plants the user might have and serves as a test
// of structs inside a `type` set.
Plant struct {
Variant string `json:"variant" jsonschema:"title=Variant"` // This comment will be ignored
Variant string `json:"variant" jsonschema:"title=Variant"` // This comment will be used
// Multicellular is true if the plant is multicellular
Multicellular bool `json:"multicellular,omitempty" jsonschema:"title=Multicellular"` // This comment will be ignored
}
)
8 changes: 7 additions & 1 deletion fixtures/go_comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
"properties": {
"variant": {
"type": "string",
"title": "Variant"
"title": "Variant",
"description": "This comment will be used"
},
"multicellular": {
"type": "boolean",
"title": "Multicellular",
"description": "Multicellular is true if the plant is multicellular"
}
},
"additionalProperties": false,
Expand Down

0 comments on commit 2bf120d

Please sign in to comment.