Web Api Help Page XML comments from more than 1 files

前端 未结 4 1029
孤街浪徒
孤街浪徒 2020-12-13 06:57

I have different plugins in my Web api project with their own XML docs, and have one centralized Help page, but the problem is that Web Api\'s default Help Page only support

4条回答
  •  囚心锁ツ
    2020-12-13 07:44

    You can modify the installed XmlDocumentationProvider at Areas\HelpPage to do something like following:

    Merge multiple Xml document files into a single one:

    Example code(is missing some error checks and validation):

    using System.Xml.Linq;
    using System.Xml.XPath;
    
     XDocument finalDoc = null;
     foreach (string file in Directory.GetFiles(@"PluginsFolder", "*.xml"))
     {
        if(finalDoc == null)
        {
            finalDoc = XDocument.Load(File.OpenRead(file));
        }
        else
        {
            XDocument xdocAdditional = XDocument.Load(File.OpenRead(file));
    
            finalDoc.Root.XPathSelectElement("/doc/members")
                         .Add(xdocAdditional.Root.XPathSelectElement("/doc/members").Elements());
        }
    }
    
    // Supply the navigator that rest of the XmlDocumentationProvider code looks for
    _documentNavigator = finalDoc.CreateNavigator();
    

提交回复
热议问题