@@ -36,14 +36,19 @@ public byte[] BuildSwaggerJson()
36
36
{
37
37
try
38
38
{
39
- if ( options . XmlDocumentPath != null && ! File . Exists ( options . XmlDocumentPath ) )
39
+ var xmlList = new List < XmlCommentStructure > ( ) ;
40
+ foreach ( var srvXml in handlers . SrvGroup )
40
41
{
41
- return Encoding . UTF8 . GetBytes ( "Xml doesn't exists at " + options . XmlDocumentPath ) ;
42
+ var xmlDocumentPath = srvXml . Value ;
43
+ xmlDocumentPath = xmlDocumentPath . Substring ( 0 , xmlDocumentPath . Length - 4 ) + ".xml" ;
44
+ if ( File . Exists ( xmlDocumentPath ) )
45
+ {
46
+ var lookUp = BuildXmlMemberCommentStructureList ( xmlDocumentPath ) ;
47
+ xmlList = xmlList . Concat ( lookUp ) . ToList ( ) ;
48
+ }
42
49
}
43
-
44
- xDocLookup = ( options . XmlDocumentPath != null )
45
- ? BuildXmlMemberCommentStructure ( options . XmlDocumentPath )
46
- : null ;
50
+ var methodList = handlers . MethodList ( ) ;
51
+ xDocLookup = xmlList . ToLookup ( x => Tuple . Create ( x . ClassName , x . MethodName ) ) ;
47
52
48
53
var doc = new SwaggerDocument ( ) ;
49
54
doc . info = options . Info ;
@@ -58,7 +63,7 @@ public byte[] BuildSwaggerJson()
58
63
? BuildXmlTypeSummary ( options . XmlDocumentPath )
59
64
: null ;
60
65
61
- doc . tags = handlers . Descriptor . Keys
66
+ doc . tags = methodList . Select ( t => t . Service . FullName ) . Distinct ( )
62
67
. Select ( x =>
63
68
{
64
69
string desc = null ;
@@ -74,13 +79,12 @@ public byte[] BuildSwaggerJson()
74
79
} )
75
80
. ToArray ( ) ;
76
81
77
- // Unary only
78
- foreach ( var item in handlers . MethodList ( ) . Where ( x => x . IsClientStreaming == false && x . IsServerStreaming == false ) )
82
+ foreach ( var item in handlers . MethodList ( ) )
79
83
{
80
84
XmlCommentStructure xmlComment = null ;
81
85
if ( xDocLookup != null )
82
86
{
83
- xmlComment = xDocLookup [ Tuple . Create ( item . Service . FullName , item . Name ) ] . FirstOrDefault ( ) ;
87
+ xmlComment = xDocLookup [ Tuple . Create ( item . Service . Name , item . Name ) ] . FirstOrDefault ( ) ;
84
88
}
85
89
86
90
var parameters = BuildParameters ( doc . definitions , xmlComment , item ) ;
@@ -354,6 +358,37 @@ private static Type GetCollectionType(Type type)
354
358
return null ; // not collection
355
359
}
356
360
361
+ private static IEnumerable < XmlCommentStructure > BuildXmlMemberCommentStructureList ( string xmlDocumentPath )
362
+ {
363
+ var file = File . ReadAllText ( xmlDocumentPath ) ;
364
+ var xDoc = XDocument . Parse ( file ) ;
365
+ var xDocLookup = xDoc . Descendants ( "member" )
366
+ . Where ( x => x . Attribute ( "name" ) . Value . StartsWith ( "M:" ) )
367
+ . Select ( x =>
368
+ {
369
+ var match = Regex . Match ( x . Attribute ( "name" ) . Value , @"(\w+)\.(\w+)?(\(.+\)|$)" ) ;
370
+
371
+ var summary = ( ( string ) x . Element ( "summary" ) ) ?? "" ;
372
+ var returns = ( ( string ) x . Element ( "returns" ) ) ?? "" ;
373
+ var remarks = ( ( string ) x . Element ( "remarks" ) ) ?? "" ;
374
+ var parameters = x . Elements ( "param" )
375
+ . Select ( e => Tuple . Create ( e . Attribute ( "name" ) . Value , e ) )
376
+ . Distinct ( new Item1EqualityCompaerer < string , XElement > ( ) )
377
+ . ToDictionary ( e => e . Item1 , e => e . Item2 . Value . Trim ( ) ) ;
378
+
379
+ return new XmlCommentStructure
380
+ {
381
+ ClassName = match . Groups [ 1 ] . Value ,
382
+ MethodName = match . Groups [ 2 ] . Value ,
383
+ Summary = summary . Trim ( ) ,
384
+ Remarks = remarks . Trim ( ) ,
385
+ Parameters = parameters ,
386
+ Returns = returns . Trim ( )
387
+ } ;
388
+ } ) ;
389
+ return xDocLookup ;
390
+ }
391
+
357
392
private static ILookup < Tuple < string , string > , XmlCommentStructure > BuildXmlMemberCommentStructure ( string xmlDocumentPath )
358
393
{
359
394
var file = File . ReadAllText ( xmlDocumentPath ) ;
0 commit comments