diff --git a/comment_extractor.go b/comment_extractor.go index 0088b41..e157837 100644 --- a/comment_extractor.go +++ b/comment_extractor.go @@ -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()) { diff --git a/examples/nested/nested.go b/examples/nested/nested.go index 886c5cf..bfdceb3 100644 --- a/examples/nested/nested.go +++ b/examples/nested/nested.go @@ -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 } ) diff --git a/fixtures/go_comments.json b/fixtures/go_comments.json index 2e675cc..bfe5e61 100644 --- a/fixtures/go_comments.json +++ b/fixtures/go_comments.json @@ -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,