Web Api Help 引用其他專案Model, Description是空的
在開發時 Model 會放在另一個專案
但在建立API說明文件時
會導致Model的說明文件沒有匯入
首先將 Model 的文件改到 WebApi 的文件路徑
WebApi的文件路徑: ~/App_Data/XmlDocument.XML
Model的文件路徑: ../WebApi專案名稱/App_Data/XmlDocument2.XML
文件路徑設置請參考: 連結
開啟: WebApi專案>Areas>HelpPage>App_Start>HelpPageConfig.cs
修改
開啟: WebApi專案>Areas>HelpPage>XmlDocumentationProvider.cs
加入
在建構式裡修改
接著加入方法
將 private XPathNavigator _documentNavigator; 移除
這時會有三行出現錯誤
這時把 _documentNavigator.SelectSingleNode 替換成 SelectSingleNode
這樣就可以解決問題了
參考來源
但在建立API說明文件時
會導致Model的說明文件沒有匯入
首先將 Model 的文件改到 WebApi 的文件路徑
WebApi的文件路徑: ~/App_Data/XmlDocument.XML
Model的文件路徑: ../WebApi專案名稱/App_Data/XmlDocument2.XML
文件路徑設置請參考: 連結
開啟: WebApi專案>Areas>HelpPage>App_Start>HelpPageConfig.cs
修改
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.XML")));
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data")));
開啟: WebApi專案>Areas>HelpPage>XmlDocumentationProvider.cs
加入
private List<XPathNavigator> _documentNavigators = new List<XPathNavigator>();
在建構式裡修改
public XmlDocumentationProvider(string documentPath)
{
if (documentPath == null)
{
throw new ArgumentNullException("documentPath");
}
//XPathDocument xpath = new XPathDocument(documentPath);
//_documentNavigator = xpath.CreateNavigator();
var files = Directory.GetFiles(documentPath, "*.xml");
foreach (var file in files)
{
XPathDocument xpath = new XPathDocument(Path.Combine(documentPath, file));
_documentNavigators.Add(xpath.CreateNavigator());
}
}
接著加入方法
private XPathNavigator SelectSingleNode(string selectExpression)
{
foreach (var navigator in _documentNavigators)
{
var propertyNode = navigator.SelectSingleNode(selectExpression);
if (propertyNode != null)
return propertyNode;
}
return null;
}
將 private XPathNavigator _documentNavigator; 移除
這時會有三行出現錯誤
這時把 _documentNavigator.SelectSingleNode 替換成 SelectSingleNode
這樣就可以解決問題了
參考來源
留言
張貼留言