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

Use inline comment if no other comment is available #94

Merged
merged 3 commits into from
Sep 28, 2023
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
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