Beispiel #1
0
        private void SetupDocumentation()
        {
            //GETs
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "untappdId/{ID}", "URL",
                                                  "JSON payload",
                                                  typeof(Beer)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "beerId/{ID}", "URL",
                                                  "JSON payload",
                                                  typeof(Beer)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "breweryId/{ID}", "URL",
                                                  "JSON payload",
                                                  typeof(ICollection <Beer>)));

            //POSTs
            EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "add/", "JSON payload",
                                                  "BeerId - int",
                                                  typeof(Beer)));
            EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "update/", "JSON payload",
                                                  "Updated Beer - JSON payload", typeof(Beer)));
        }
        private void SetupDocumentation()
        {
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "userId/{ID}", "URL",
                                                  "Review Collection - JSON payload", typeof(ICollection <UserBeerRanking>)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "userId/{USERID}/beerId/{BEERID}", "URL",
                                                  "Review Collection - JSON payload", typeof(UserBeerRanking)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "beerId/{ID}", "URL", "Review Collection - Json",
                                                  typeof(ICollection <UserBeerRanking>)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "beerId/{BEERID}/userId/{USERID}", "URL",
                                                  "Review Collection - JSON payload", typeof(UserBeerRanking)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "untappdId/{ID}", "URL",
                                                  "Review Collection - JSON payload", typeof(ICollection <UserBeerRanking>)));

            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "breweryDbId/{ID}", "URL",
                                                  "Review Collection - JSON payload", typeof(ICollection <UserBeerRanking>)));

            EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "add/", "JSON payload", "Status - boolean",
                                                  typeof(bool)));
            EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "update/", "JSON payload",
                                                  "Updated Review - JSON payload", typeof(UserBeerRanking)));
        }
        private void SetupDocumentation()
        {
            //GETs
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "id/{ID}?GetBeers={bool}",
                                                  "URL",
                                                  "Brewery - JSON payload", typeof(Brewery)));
            EndpointDocumentation.Add(new RestDoc("GET",
                                                  UrlSegment + "untappdId/{ID}?GetBeers={bool}", "URL",
                                                  "Brewery - JSON payload", typeof(Brewery)));
            EndpointDocumentation.Add(new RestDoc("GET",
                                                  UrlSegment + "breweryDbId/{ID}?GetBeers={bool}", "URL",
                                                  "Brewery - JSON payload", typeof(Brewery)));
            EndpointDocumentation.Add(new RestDoc("GET", UrlSegment + "all?GetBeers={bool}", "URL",
                                                  "Brewery Collection - JSON payload", typeof(ICollection <Brewery>)));

            //POSTs
            EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "add", "JSON payload",
                                                  "Brewery - JSON payload",
                                                  typeof(Brewery)));
            EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "update", "JSON payload",
                                                  "Brewery - JSON payload", typeof(Brewery)));
        }
 private void SetupDocumentation()
 {
     EndpointDocumentation.Add(new RestDoc("GET",
                                           UrlSegment + "userId/{ID}", "URL", "UserInfo - JSON Payload",
                                           typeof(UserInfo)));
     EndpointDocumentation.Add(new RestDoc("GET",
                                           UrlSegment + "untappdId/{ID}", "URL",
                                           "UserInfo - JSON Payload", typeof(UserInfo)));
     EndpointDocumentation.Add(new RestDoc("GET",
                                           UrlSegment + "firstname/{name}", "URL",
                                           "UserInfo - JSON Payload", typeof(UserInfo)));
     EndpointDocumentation.Add(new RestDoc("GET",
                                           UrlSegment + "lastname/{name}", "URL",
                                           "UserInfo - JSON Payload", typeof(UserInfo)));
     EndpointDocumentation.Add(new RestDoc("GET",
                                           UrlSegment + "location/{location}", "URL",
                                           "UserInfo - JSON Payload", typeof(UserInfo)));
     EndpointDocumentation.Add(new RestDoc("POST", UrlSegment + "add/",
                                           "JSON Payload", "UserId - int",
                                           typeof(UserInfo)));
     EndpointDocumentation.Add(new RestDoc("POST",
                                           UrlSegment + "update/", "JSON Payload",
                                           "JSON Payload - Updated UserInfo", typeof(UserInfo)));
 }
Beispiel #5
0
        IList <IEndpointDocumentation> IRequestRouter.GetEndpointDocumentation()
        {
            List <Registration> registrations;

            lock (_registrations)
                registrations = _registrations.ToList();

            var endpoints = new List <IEndpointDocumentation>();

            foreach (var registration in registrations.Where(r => r.TestScenarioName == null))
            {
                var endpointDocumentation = new EndpointDocumentation
                {
                    RelativePath = registration.Filter.Description
                };

                if (registration.Router != null)
                {
                    var routerEndpoints = registration.Router.GetEndpointDocumentation();
                    endpoints.AddRange(routerEndpoints);
                    continue;
                }

                var documented = registration.Runable as IDocumented;
                if (documented != null)
                {
                    endpointDocumentation.Description = documented.Description;
                    endpointDocumentation.Examples    = documented.Examples;
                    endpointDocumentation.Attributes  = documented.Attributes;
                }

                object[] customAttributes = null;
                if (registration.Method != null)
                {
                    customAttributes = registration.Method.GetCustomAttributes(true)
                                       .Concat(
                        registration.Method.GetParameters()
                        .Skip(1)
                        .Select(p => new
                    {
                        parameter = p,
                        attribute = p.GetCustomAttributes(false).Select(a => a as EndpointParameterAttribute).FirstOrDefault(a => a != null)
                    })
                        .Select(o =>
                    {
                        var attribute = o.attribute;

                        if (attribute == null)
                        {
                            attribute = new EndpointParameterAttribute
                            {
                                ParameterType = EndpointParameterType.QueryString
                            }
                        }
                        ;

                        if (string.IsNullOrEmpty(attribute.ParameterName))
                        {
                            attribute.ParameterName = o.parameter.Name;
                        }

                        if (attribute.ParserType == null)
                        {
                            attribute.ParserType = o.parameter.ParameterType;
                        }

                        return(attribute);
                    }))
                                       .ToArray();
                }
                else if (registration.DeclaringType != null)
                {
                    customAttributes = registration.DeclaringType.GetCustomAttributes(true);
                }

                string endpointPath       = null;
                string queryStringExample = null;

                if (customAttributes != null)
                {
                    foreach (var attribute in customAttributes)
                    {
                        var description = attribute as DescriptionAttribute;
                        if (description != null)
                        {
                            endpointDocumentation.Description = endpointDocumentation.Description == null
                                ? description.Html
                                : (endpointDocumentation.Description + "<br>" + description.Html);
                        }

                        var example = attribute as ExampleAttribute;
                        if (example != null)
                        {
                            endpointDocumentation.Examples = endpointDocumentation.Examples == null
                                ? example.Html
                                : (endpointDocumentation.Examples + "<br>" + example.Html);
                        }

                        var option = attribute as OptionAttribute;
                        if (option != null)
                        {
                            if (endpointDocumentation.Attributes == null)
                            {
                                endpointDocumentation.Attributes = new List <IEndpointAttributeDocumentation>();
                            }

                            endpointDocumentation.Attributes.Add(new EndpointAttributeDocumentation
                            {
                                Type        = option.OptionType.ToString(),
                                Name        = option.Name,
                                Description = option.Html
                            });
                        }

                        var endpoint = attribute as EndpointAttribute;
                        if (endpoint != null)
                        {
                            endpointPath = endpoint.UrlPath;
                        }

                        var endpointParameter = attribute as EndpointParameterAttribute;
                        if (endpointParameter != null)
                        {
                            if (endpointDocumentation.Attributes == null)
                            {
                                endpointDocumentation.Attributes = new List <IEndpointAttributeDocumentation>();
                            }

                            var parameterValue       = "{" + endpointParameter.ParameterName + "}";
                            var parameterDescription = endpointParameter.ParserType.DisplayName();

                            if (typeof(IDocumented).IsAssignableFrom(endpointParameter.ParserType) ||
                                typeof(IParameterParser).IsAssignableFrom(endpointParameter.ParserType))
                            {
                                var constructor = endpointParameter.ParserType.GetConstructor(Type.EmptyTypes);
                                if (constructor != null)
                                {
                                    var parser = constructor.Invoke(null);
                                    var parameterDocumented = parser as IDocumented;
                                    var parameterParser     = parser as IParameterParser;

                                    if (parameterDocumented != null)
                                    {
                                        parameterDescription = parameterDocumented.Description;
                                        parameterValue       = parameterDocumented.Examples;
                                    }
                                    else if (parameterParser != null)
                                    {
                                        parameterDescription = parameterParser.Description;
                                    }
                                }
                                if (!string.IsNullOrEmpty((endpointParameter.Description)))
                                {
                                    parameterDescription = endpointParameter.Description;
                                }
                            }

                            if (endpointParameter.ParameterType.HasFlag(EndpointParameterType.QueryString))
                            {
                                if (queryStringExample == null)
                                {
                                    queryStringExample = "?" + endpointParameter.ParameterName + "=" + parameterValue;
                                }
                                else
                                {
                                    queryStringExample += "&" + endpointParameter.ParameterName + "=" + parameterValue;
                                }
                            }


                            endpointDocumentation.Attributes.Add(new EndpointAttributeDocumentation
                            {
                                Type        = endpointParameter.ParameterType.ToString(),
                                Name        = endpointParameter.ParameterName,
                                Description = parameterDescription
                            });
                        }
                    }
                }

                if (string.IsNullOrEmpty(endpointDocumentation.Examples) && !string.IsNullOrEmpty(endpointPath))
                {
                    endpointDocumentation.Examples = endpointPath;
                    if (!string.IsNullOrEmpty(queryStringExample))
                    {
                        endpointDocumentation.Examples += queryStringExample;
                    }
                }

                endpoints.Add(endpointDocumentation);
            }

            return(endpoints);
        }
Beispiel #6
0
        IList <IEndpointDocumentation> IRequestRouter.GetEndpointDocumentation()
        {
            List <Registration> registrations;

            lock (_registrations)
                registrations = _registrations.ToList();

            var endpoints = new List <IEndpointDocumentation>();

            foreach (var registration in registrations)
            {
                var endpoint = new EndpointDocumentation
                {
                    RelativePath = registration.Filter.Description
                };

                if (registration.Router != null)
                {
                    var routerEndpoints = registration.Router.GetEndpointDocumentation();
                    endpoints.AddRange(routerEndpoints);
                    continue;
                }

                if (registration.Runable != null)
                {
                    var documented = registration.Runable as IDocumented;
                    if (documented != null)
                    {
                        endpoint.Description = documented.Description;
                        endpoint.Examples    = documented.Examples;
                        endpoint.Attributes  = documented.Attributes;
                    }
                }

                if (registration.DeclaringType != null)
                {
                    foreach (var attribute in registration.DeclaringType.GetCustomAttributes(true))
                    {
                        var description = attribute as DescriptionAttribute;
                        if (description != null)
                        {
                            endpoint.Description = endpoint.Description == null
                                ? description.Html
                                : (endpoint.Description + "<br>" + description.Html);
                        }

                        var example = attribute as ExampleAttribute;
                        if (example != null)
                        {
                            endpoint.Examples = endpoint.Examples == null
                                ? example.Html
                                : (endpoint.Examples + "<br>" + example.Html);
                        }

                        var option = attribute as OptionAttribute;
                        if (option != null)
                        {
                            if (endpoint.Attributes == null)
                            {
                                endpoint.Attributes = new List <IEndpointAttributeDocumentation>();
                            }

                            endpoint.Attributes.Add(new EndpointAttributeDocumentation
                            {
                                Type        = option.OptionType.ToString(),
                                Name        = option.Name,
                                Description = option.Html
                            });
                        }
                    }
                }

                endpoints.Add(endpoint);
            }

            return(endpoints);
        }