asp.net mvc 4 - Web API Help pages - customizing Property documentation -
i have web api , added web api pages auto-generate documentation. it's working great methods parameters listed out, have method this:
public sessionresult postlogin(createsessioncommand request)
and, on page, listing command parameter in properties section. however, in sample request section, lists out of properties of createsessioncommand
class.
parameters
name | description | additional information
request | no documentation available. | define parameter in request body.
i instead list of properties in createsessioncommand
class. there easy way this?
this should go addition @josh answer. if want not list properties model class, include documentation each property, areas/helppage/xmldocumentationprovider.cs file should modified follows:
public virtual string getdocumentation(httpparameterdescriptor parameterdescriptor) { reflectedhttpparameterdescriptor reflectedparameterdescriptor = parameterdescriptor reflectedhttpparameterdescriptor; if (reflectedparameterdescriptor != null) { if (reflectedparameterdescriptor.parameterinfo customparameterinfo) { const string propertyexpression = "/doc/members/member[@name='p:{0}']"; var pi = (customparameterinfo) reflectedparameterdescriptor.parameterinfo; string selectexpression = string.format(cultureinfo.invariantculture, propertyexpression, pi.prop.declaringtype.fullname + "." + pi.prop.name); xpathnavigator methodnode = _documentnavigator.selectsinglenode(selectexpression); if (methodnode != null) { return methodnode.value.trim(); } } else { xpathnavigator methodnode = getmethodnode(reflectedparameterdescriptor.actiondescriptor); if (methodnode != null) { string parametername = reflectedparameterdescriptor.parameterinfo.name; xpathnavigator parameternode = methodnode.selectsinglenode(string.format(cultureinfo.invariantculture, parameterexpression, parametername)); if (parameternode != null) { return parameternode.value.trim(); } } } } return null; }
and customparameterinfo class should keep property info well:
internal class customparameterinfo : parameterinfo { public propertyinfo prop { get; private set; } public customparameterinfo(propertyinfo prop) { prop = prop; base.nameimpl = prop.name; } }
Comments
Post a Comment