Inheritance: IRestPath
        private MethodDescription FormateMethodDescription(RestPath restPath)
        {
            var verbs = new List<string>();
            var summary = restPath.Summary;
            var notes = restPath.Notes;

            if (restPath.AllowsAllVerbs)
            {
                verbs.AddRange(new[] { "GET", "POST", "PUT", "DELETE" });
            }
            else
                verbs.AddRange(restPath.AllowedVerbs.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));

            var nickName = nicknameCleanerRegex.Replace(restPath.Path, "");

            var md = new MethodDescription {
                Path = restPath.Path,
                Description = summary,
                Operations = verbs.Select(verb =>
                    new MethodOperation {
                        HttpMethod = verb,
                        Nickname = verb.ToLowerInvariant() + nickName,
                        Summary = summary,
                        Notes = notes,
                        Parameters = ParseParameters(verb, restPath.RequestType)
                    }).ToList()
            };
            return md;
        }
Example #2
0
        public void RegisterRestPath(RestPath restPath)
        {
            List <RestPath> pathsAtFirstMatch;

            if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch))
            {
                pathsAtFirstMatch = new List <RestPath>();
                RestPathMap[restPath.FirstMatchHashKey] = pathsAtFirstMatch;
            }
            pathsAtFirstMatch.Add(restPath);
        }
Example #3
0
        public void RegisterRestPaths(Type requestType)
        {
            var attrs = requestType.GetCustomAttributes(typeof(RouteAttribute), true);

            foreach (RouteAttribute attr in attrs)
            {
                var restPath = new RestPath(requestType, attr.Path, attr.Verbs);
                if (!restPath.IsValid)
                {
                    throw new NotSupportedException(string.Format(
                                                        "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.Name));
                }

                RegisterRestPath(restPath);
            }
        }
        public void RegisterRestPaths(Type requestType)
        {
            var attrs = TypeDescriptor.GetAttributes(requestType).OfType <RouteAttribute>();

            foreach (RouteAttribute attr in attrs)
            {
                var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes);
                if (!restPath.IsValid)
                {
                    throw new NotSupportedException(string.Format(
                                                        "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.Name));
                }

                RegisterRestPath(restPath);
            }
        }
        public void Can_deserialize_TestRequest_QueryStringSerializer_output()
        {
            // Setup
            var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly);
            var restPath = new RestPath(typeof(TestRequest), "/service", "GET");
            var restHandler = new RestHandler { RestPath = restPath };

            var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}";
            NameValueCollection queryString = HttpUtility.ParseQueryString(requestString);
            var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection());

            var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service");

            Assert.That(request2.ListOfA.Count, Is.EqualTo(1));
            Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2));
        }
Example #6
0
        public IRestPath GetRestPathForRequest(string httpMethod, string pathInfo)
        {
            var matchUsingPathParts = RestPath.GetPathPartsForMatching(pathInfo);

            List <RestPath> firstMatches;

            var yieldedHashMatches = RestPath.GetFirstMatchHashKeys(matchUsingPathParts);

            foreach (var potentialHashMatch in yieldedHashMatches)
            {
                if (!this.RestPathMap.TryGetValue(potentialHashMatch, out firstMatches))
                {
                    continue;
                }

                foreach (var restPath in firstMatches)
                {
                    if (restPath.IsMatch(httpMethod, matchUsingPathParts))
                    {
                        return(restPath);
                    }
                }
            }

            var yieldedWildcardMatches = RestPath.GetFirstMatchWildCardHashKeys(matchUsingPathParts);

            foreach (var potentialHashMatch in yieldedWildcardMatches)
            {
                if (!this.RestPathMap.TryGetValue(potentialHashMatch, out firstMatches))
                {
                    continue;
                }

                foreach (var restPath in firstMatches)
                {
                    if (restPath.IsMatch(httpMethod, matchUsingPathParts))
                    {
                        return(restPath);
                    }
                }
            }

            return(null);
        }
        public void RegisterRestPaths(Type requestType, Type serviceType)
        {
            var attrs = requestType.GetCustomAttributes(typeof(RestServiceAttribute), true);

            foreach (RestServiceAttribute attr in attrs)
            {
                var restPath = new RestPath(requestType, attr);
                if (!restPath.IsValid)
                {
                    throw new NotSupportedException(string.Format(
                                                        "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.Name));
                }

                List <RestPath> pathsAtFirstMatch;
                if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch))
                {
                    pathsAtFirstMatch = new List <RestPath>();
                    RestPathMap[restPath.FirstMatchHashKey] = pathsAtFirstMatch;
                }
                pathsAtFirstMatch.Add(restPath);
            }
        }
        public void RegisterRestPaths(Type requestType)
        {
            var attrs = TypeDescriptor.GetAttributes(requestType).OfType <RouteAttribute>();

            foreach (RouteAttribute attr in attrs)
            {
                var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes);

                var defaultAttr = attr as FallbackRouteAttribute;
                if (defaultAttr != null)
                {
                    if (EndpointHost.Config != null)
                    {
                        if (EndpointHost.Config.FallbackRestPath != null)
                        {
                            throw new NotSupportedException(string.Format(
                                                                "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed."));
                        }

                        EndpointHost.Config.FallbackRestPath = (httpMethod, pathInfo, filePath) =>
                        {
                            var pathInfoParts = RestPath.GetPathPartsForMatching(pathInfo);
                            return(restPath.IsMatch(httpMethod, pathInfoParts) ? restPath : null);
                        };
                    }

                    continue;
                }

                if (!restPath.IsValid)
                {
                    throw new NotSupportedException(string.Format(
                                                        "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.Name));
                }

                RegisterRestPath(restPath);
            }
        }
        public void RegisterRestPath(RestPath restPath)
        {
            if (!EndpointHostConfig.SkipRouteValidation)
            {
                if (!restPath.Path.StartsWith("/"))
                {
                    throw new ArgumentException("Route '{0}' on '{1}' must start with a '/'".Fmt(restPath.Path, restPath.RequestType.Name));
                }
                if (restPath.Path.IndexOfAny(InvalidRouteChars) != -1)
                {
                    throw new ArgumentException(("Route '{0}' on '{1}' contains invalid chars. " +
                                                 "See https://github.com/ServiceStack/ServiceStack/wiki/Routing for info on valid routes.").Fmt(restPath.Path, restPath.RequestType.Name));
                }
            }

            List <RestPath> pathsAtFirstMatch;

            if (!RestPathMap.TryGetValue(restPath.FirstMatchHashKey, out pathsAtFirstMatch))
            {
                pathsAtFirstMatch = new List <RestPath>();
                RestPathMap[restPath.FirstMatchHashKey] = pathsAtFirstMatch;
            }
            pathsAtFirstMatch.Add(restPath);
        }