Reputation: 45
I need to dynamically generate the help for some WEB-API. The problem is that are dynamic both in the input parameters that in the structure of output.
See the Example:
[HttpGet]
[Route("API/Individuals")]
[ActionName("Individuals")]
public HttpResponseMessage Select()
{
var Params = this.Request.RequestUri.ParseQueryString();
string UserNameCVT = Code.RemappingUser.Remap(UserName.Name);
DataSet ds = Models.Individuals.Individuals.SelectDS(UserNameCVT, Params);
List<Dictionary<string, object>> lDict = DecodeIndividualsFromDS(ds);
response = Request.CreateResponse(HttpStatusCode.OK, lDict);
return response;
}
By doing this, the API is to decouple that from FE DB below, leaving them free to modify the data structures according to their needs.
Is it possible to generate a complete Help once the structures are defined (without changing the code of the API)?
Upvotes: 3
Views: 125
Reputation: 156898
Yes, you can. The key line of code in the XML documentation provider is this (from this getting started page):
config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
As you see, the documentation is read from a file path. If you can dynamically create that file on the start of your application, and then pass in the file path, you are set. (You have to find a way to handle those end points dynamically, but that is not in the scope of this question)
Also, if you need to do more, you can create a custom implementation by taking the XmlDocumentationProvider
from Github and write your own.
Upvotes: 1