Esempio n. 1
0
        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 : "");
        }
Esempio n. 2
0
        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 : "");
        }
Esempio n. 3
0
        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) : "");
        }
Esempio n. 4
0
        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 : "");
        }
Esempio n. 5
0
        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) : "");
        }
Esempio n. 6
0
        private string Method_Route(DocumentorContext context, params object[] parameters)
        {
            MethodInfo      restMethod = parameters[0] as MethodInfo;
            MethodAttribute attr       = restMethod.GetRadishAttribute <MethodAttribute>();

            return(attr.Route);
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        /// <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();
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
        /// <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());
        }
Esempio n. 13
0
        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());
        }
Esempio n. 14
0
        private string ResponseCode_Description(DocumentorContext context, params object[] parameters)
        {
            ResponseCodeAttribute attr = parameters[0] as ResponseCodeAttribute;

            return(attr.Description);
        }
Esempio n. 15
0
        private string ResponseCode_Code(DocumentorContext context, params object[] parameters)
        {
            ResponseCodeAttribute attr = parameters[0] as ResponseCodeAttribute;

            return(attr.Code.ToString());
        }
Esempio n. 16
0
        private string RequestParameter_Required(DocumentorContext context, params object[] parameters)
        {
            RequestParameterAttribute attr = parameters[0] as RequestParameterAttribute;

            return(attr.Required.ToString());
        }
Esempio n. 17
0
        private string RequestParameter_Type(DocumentorContext context, params object[] parameters)
        {
            RequestParameterAttribute attr = parameters[0] as RequestParameterAttribute;

            return(attr.Type);
        }
Esempio n. 18
0
 private string Page_Title(DocumentorContext context, params object[] parameters)
 {
     return(context.RenderTemplate <BasicTemplateSet>(ts => ts.Title));
 }