@@ -1294,7 +1294,10 @@ func (parser *Parser) ParseDefinition(typeSpecDef *TypeSpecDef) (*Schema, error)
12941294 }
12951295
12961296 if definition .Description == "" {
1297- fillDefinitionDescription (definition , typeSpecDef .File , typeSpecDef )
1297+ err = parser .fillDefinitionDescription (definition , typeSpecDef .File , typeSpecDef )
1298+ if err != nil {
1299+ return nil , err
1300+ }
12981301 }
12991302
13001303 if len (typeSpecDef .Enums ) > 0 {
@@ -1344,7 +1347,7 @@ func fullTypeName(parts ...string) string {
13441347
13451348// fillDefinitionDescription additionally fills fields in definition (spec.Schema)
13461349// TODO: If .go file contains many types, it may work for a long time
1347- func fillDefinitionDescription (definition * spec.Schema , file * ast.File , typeSpecDef * TypeSpecDef ) {
1350+ func ( parser * Parser ) fillDefinitionDescription (definition * spec.Schema , file * ast.File , typeSpecDef * TypeSpecDef ) ( err error ) {
13481351 if file == nil {
13491352 return
13501353 }
@@ -1359,16 +1362,23 @@ func fillDefinitionDescription(definition *spec.Schema, file *ast.File, typeSpec
13591362 if ! ok || typeSpec != typeSpecDef .TypeSpec {
13601363 continue
13611364 }
1362-
1363- definition .Description =
1364- extractDeclarationDescription (typeSpec .Doc , typeSpec .Comment , generalDeclaration .Doc )
1365+ var typeName string
1366+ if typeSpec .Name != nil {
1367+ typeName = typeSpec .Name .Name
1368+ }
1369+ definition .Description , err =
1370+ parser .extractDeclarationDescription (typeName , typeSpec .Doc , typeSpec .Comment , generalDeclaration .Doc )
1371+ if err != nil {
1372+ return
1373+ }
13651374 }
13661375 }
1376+ return nil
13671377}
13681378
13691379// extractDeclarationDescription gets first description
13701380// from attribute descriptionAttr in commentGroups (ast.CommentGroup)
1371- func extractDeclarationDescription (commentGroups ... * ast.CommentGroup ) string {
1381+ func ( parser * Parser ) extractDeclarationDescription (typeName string , commentGroups ... * ast.CommentGroup ) ( string , error ) {
13721382 var description string
13731383
13741384 for _ , commentGroup := range commentGroups {
@@ -1383,9 +1393,23 @@ func extractDeclarationDescription(commentGroups ...*ast.CommentGroup) string {
13831393 if len (commentText ) == 0 {
13841394 continue
13851395 }
1386- attribute := FieldsByAnySpace (commentText , 2 )[0 ]
1396+ fields := FieldsByAnySpace (commentText , 2 )
1397+ attribute := fields [0 ]
13871398
1388- if strings .ToLower (attribute ) != descriptionAttr {
1399+ if attr := strings .ToLower (attribute ); attr == descriptionMarkdownAttr {
1400+ if len (fields ) > 1 {
1401+ typeName = fields [1 ]
1402+ }
1403+ if typeName == "" {
1404+ continue
1405+ }
1406+ desc , err := getMarkdownForTag (typeName , parser .markdownFileDir )
1407+ if err != nil {
1408+ return "" , err
1409+ }
1410+ // if found markdown description, we will only use the markdown file content
1411+ return string (desc ), nil
1412+ } else if attr != descriptionAttr {
13891413 if ! isHandlingDescription {
13901414 continue
13911415 }
@@ -1398,7 +1422,7 @@ func extractDeclarationDescription(commentGroups ...*ast.CommentGroup) string {
13981422 }
13991423 }
14001424
1401- return strings .TrimLeft (description , " " )
1425+ return strings .TrimLeft (description , " " ), nil
14021426}
14031427
14041428// parseTypeExpr parses given type expression that corresponds to the type under
0 commit comments