예제 #1
0
        private IEnumerable <Property> GetSecurityParameters(Operation method)
        {
            var securityParams = new Collection <Property>();

            var securedBy = method.Security != null && method.Security.Any() ? method.Security : null;

            if (securedBy == null)
            {
                return(securityParams);
            }

            var secured = securedBy.First(); //TODO: check, how to choose ?

            return(queryParametersParser.ConvertParametersToProperties(secured.QueryParameters));
        }
        public void Generate(EndPoint resource, string url, ClientGeneratorMethod clientGeneratorMethod,
                             IDictionary <string, ApiObject> uriParameterObjects, IDictionary <string, Parameter> parentUriParameters)
        {
            var parameters = GetUriParameters(resource, url, parentUriParameters).ToArray();

            clientGeneratorMethod.UriParameters = parameters;

            if (!parameters.Any())
            {
                return;
            }

            var name = NetNamingMapper.GetObjectName(url) + "UriParameters";

            clientGeneratorMethod.UriParametersType = name;
            if (uriParameterObjects.ContainsKey(name))
            {
                return;
            }

            var properties = new List <Property>();

            if (resource.Parameters != null)
            {
                properties.AddRange(queryParametersParser.ConvertParametersToProperties(resource.Parameters));
            }

            var urlParameters     = ExtractParametersFromUrl(url).ToArray();
            var matchedParameters = MatchParameters(parentUriParameters, urlParameters);

            foreach (var urlParameter in matchedParameters)
            {
                var property = ConvertGeneratorParamToProperty(urlParameter);
                if (properties.All(p => !String.Equals(property.Name, p.Name, StringComparison.InvariantCultureIgnoreCase)))
                {
                    properties.Add(property);
                }
            }

            var apiObject = new ApiObject
            {
                Name        = name,
                Description = "Uri Parameters for resource " + resource.Path,
                Properties  = properties
            };

            uriParameterObjects.Add(name, apiObject);
        }