private string ResponseBody_Description(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; ResponseBodyDescriptionAttribute attr = restMethod.GetRadishAttribute <ResponseBodyDescriptionAttribute>(); return(attr != null ? attr.Description : ""); }
private string RequestBody_Data(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; RequestBodyExampleAttribute attr = restMethod.GetRadishAttribute <RequestBodyExampleAttribute>(); return(attr != null ? attr.Data : ""); }
private string Method_ResponseCodesList(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; bool hasResponseCodes = restMethod.GetRadishAttributes <ResponseCodeAttribute>().Count() > 0; return(hasResponseCodes ? context.RenderTemplate <BasicTemplateSet>(ts => ts.ResponseCodesList, restMethod) : ""); }
private string Method_Title(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; MethodTitleAttribute attr = restMethod.GetRadishAttribute <MethodTitleAttribute>(); return(attr != null ? attr.Title : ""); }
private string Method_ResponseBodyExample(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; ResponseBodyExampleAttribute attr = restMethod.GetRadishAttribute <ResponseBodyExampleAttribute>(); return(attr != null ? context.RenderTemplate <BasicTemplateSet>(ts => ts.ResponseBodyExample, restMethod) : ""); }
private string Method_Route(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; MethodAttribute attr = restMethod.GetRadishAttribute <MethodAttribute>(); return(attr.Route); }
private string Page_JsonMethodsList(DocumentorContext context, params object[] parameters) { StringBuilder sbMethods = new StringBuilder(); foreach (MethodInfo methodInfo in context.RestMethods) { string title = ""; string method = ""; string route = ""; string id = ""; MethodAttribute attrMethod = methodInfo.GetRadishAttribute <MethodAttribute>(); if (attrMethod != null) { id = attrMethod.Id; route = attrMethod.Route; method = attrMethod.MethodType; } MethodTitleAttribute attrTitle = methodInfo.GetRadishAttribute <MethodTitleAttribute>(); if (attrTitle != null) { title = attrTitle.Title; } sbMethods.Append( String.Format("{{\"title\": \"{0}\", \"method\" : \"{1}\", \"route\": \"{2}\", \"id\" : \"{3}\"}},\n", title, method, route, id)); } return(sbMethods.ToString()); }
private string MethodsGroup_Description(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; OrderAttribute attr = restMethod.GetRadishAttribute <OrderAttribute>(); MethodGroup group = context.MethodGroups[attr.GroupKey]; return(group.Description); }
/// <summary> /// Initializes new Documentor instance. /// REST methods will be looked for in the specified assemblies. /// </summary> public Documentor(params Assembly[] assemblies) { // set assemblies to look for REST methods RestApiAssemblies = assemblies; // initiate context mContext = new DocumentorContext(this); // default template set TemplateSet = new SimpleTemplateSet(); }
private string ResponseCodesList_ResponseCodesList(DocumentorContext context, params object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; IEnumerable <ResponseCodeAttribute> attrResponseCodes = restMethod.GetRadishAttributes <ResponseCodeAttribute>().OrderBy(rc => rc.Code); StringBuilder sbResponseCodesList = new StringBuilder(); foreach (ResponseCodeAttribute attr in attrResponseCodes) { sbResponseCodesList.Append(context.RenderTemplate <BasicTemplateSet>(ts => ts.ResponseCode, attr)); } return(sbResponseCodesList.ToString()); }
private string RequestParametersList_RequestParametersList(DocumentorContext context, object[] parameters) { MethodInfo restMethod = parameters[0] as MethodInfo; IEnumerable <RequestParameterAttribute> attrRequestParametersList = restMethod.GetRadishAttributes <RequestParameterAttribute>().OrderBy(rp => rp.Order); StringBuilder sbRequestParametersList = new StringBuilder(); foreach (RequestParameterAttribute attr in attrRequestParametersList) { sbRequestParametersList.Append(context.RenderTemplate <BasicTemplateSet>(ts => RequestParameter, attr)); } return(sbRequestParametersList.ToString()); }
/// <summary> /// Renders specified template. /// Rendering means recursively applying all replacement rules defined for the template and nested templates. /// </summary> /// <typeparam name="T">Template set class. Should be inherited from <see cref="AbstractTemplateSet"/>.</typeparam> /// <param name="context">Documentor context</param> /// <param name="template">Expression defining template inside the template set. For example: ts => ts.Page.</param> /// <param name="parameters">Optional range of parameters to be passed into rules.</param> /// <returns>Template content as string, where tags replaced with output values according to defined rules.</returns> internal string RenderTemplate <T>(DocumentorContext context, Expression <Func <T, string> > template, params object[] parameters) where T : AbstractTemplateSet { string templateName = GetTemplateName(template); StringBuilder contentBuilder = new StringBuilder(GetTemplateContent(templateName)); IEnumerable <Rule> rulesToExecute = ReplacementRules.Where(r => r.TemplateName == templateName); foreach (Rule rule in rulesToExecute) { contentBuilder.Replace(String.Format("{{{{{0}}}}}", rule.Tag), rule.Execute(context, parameters)); } return(contentBuilder.ToString()); }
private string Page_MethodsList(DocumentorContext context, params object[] parameters) { StringBuilder sbMethods = new StringBuilder(); string latestGroupKey = null; foreach (MethodInfo method in context.RestMethods) { OrderAttribute attrOrder = method.GetRadishAttribute <OrderAttribute>(); if (attrOrder != null) { if (!String.IsNullOrEmpty(attrOrder.GroupKey) && latestGroupKey != attrOrder.GroupKey) { sbMethods.Append(context.RenderTemplate <BasicTemplateSet>(ts => ts.MethodsGroup, method)); } latestGroupKey = attrOrder.GroupKey; } sbMethods.Append(context.RenderTemplate <BasicTemplateSet>(ts => ts.Method, method)); } return(sbMethods.ToString()); }
private string ResponseCode_Description(DocumentorContext context, params object[] parameters) { ResponseCodeAttribute attr = parameters[0] as ResponseCodeAttribute; return(attr.Description); }
private string ResponseCode_Code(DocumentorContext context, params object[] parameters) { ResponseCodeAttribute attr = parameters[0] as ResponseCodeAttribute; return(attr.Code.ToString()); }
private string RequestParameter_Required(DocumentorContext context, params object[] parameters) { RequestParameterAttribute attr = parameters[0] as RequestParameterAttribute; return(attr.Required.ToString()); }
private string RequestParameter_Type(DocumentorContext context, params object[] parameters) { RequestParameterAttribute attr = parameters[0] as RequestParameterAttribute; return(attr.Type); }
private string Page_Title(DocumentorContext context, params object[] parameters) { return(context.RenderTemplate <BasicTemplateSet>(ts => ts.Title)); }