public static RestOperationParameters GetParameters(HttpRequest request)
        {
            string body;

            var formCollection = request.HasFormContentType ? request.ReadFormAsync().Result : null;

            using (var streamReader = new StreamReader(request.Body))
            {
                body = streamReader.ReadToEnd();
            }

            var parameters = string.IsNullOrEmpty(body)
                ? new RestOperationParameters() : RestOperationParameters.FromBody(body);

            parameters.RequestBody  = body;
            parameters.RequestFiles = formCollection?.Files;

            foreach (var pair in request.Query)
            {
                parameters.QueryParameters.Set(pair.Key, pair.Value[0]);
                parameters.Set(pair.Key, pair.Value[0]);
            }

            foreach (var pair in request.Headers)
            {
                parameters.Headers.Set(pair.Key, pair.Value[0]);
                parameters.Set(pair.Key, pair.Value[0]);
            }

            return(parameters);
        }
Пример #2
0
        public RestOperationParameters Omit(params string[] paths)
        {
            RestOperationParameters parameters = new RestOperationParameters();

            foreach (string path in paths)
            {
                parameters.Remove(path);
            }
            return(parameters);
        }
Пример #3
0
        public RestOperationParameters Pick(params string[] paths)
        {
            RestOperationParameters parameters = new RestOperationParameters();

            foreach (string path in paths)
            {
                if (this.ContainsKey(path))
                {
                    parameters[path] = this.Get(path);
                }
            }
            return(parameters);
        }
Пример #4
0
        public static RestOperationParameters FromBody(string json)
        {
            IDictionary <string, object> nullableMap = JsonConverter.ToNullableMap(json);

            if (nullableMap == null)
            {
                return(new RestOperationParameters());
            }
            var res = new RestOperationParameters((IDictionary)nullableMap)
            {
                BodyParameters = new AnyValueMap(nullableMap)
            };

            return(res);
        }
Пример #5
0
        public RestOperationParameters Override(RestOperationParameters parameters, bool recursive)
        {
            RestOperationParameters parameters1 = new RestOperationParameters();

            if (recursive)
            {
                RecursiveObjectWriter.CopyProperties((object)parameters1, (object)this);
                RecursiveObjectWriter.CopyProperties((object)parameters1, (object)parameters);
            }
            else
            {
                ObjectWriter.SetProperties((object)parameters1, (IDictionary <string, object>) this);
                ObjectWriter.SetProperties((object)parameters1, (IDictionary <string, object>)parameters);
            }
            return(parameters1);
        }
Пример #6
0
        public RestOperationParameters SetDefaults(RestOperationParameters defaultParameters, bool recursive)
        {
            RestOperationParameters parameters = new RestOperationParameters();

            if (recursive)
            {
                RecursiveObjectWriter.CopyProperties((object)parameters, (object)defaultParameters);
                RecursiveObjectWriter.CopyProperties((object)parameters, (object)this);
            }
            else
            {
                ObjectWriter.SetProperties((object)parameters, (IDictionary <string, object>)defaultParameters);
                ObjectWriter.SetProperties((object)parameters, (IDictionary <string, object>) this);
            }
            return(parameters);
        }
Пример #7
0
 public RestOperationParameters Override(RestOperationParameters parameters)
 {
     return(this.Override(parameters, false));
 }
Пример #8
0
 public RestOperationParameters GetAsParametersWithDefault(string key, RestOperationParameters defaultValue)
 {
     return(this.GetAsNullableParameters(key) ?? defaultValue);
 }
Пример #9
0
 public RestOperationParameters SetDefaults(RestOperationParameters defaultParameters)
 {
     return(this.SetDefaults(defaultParameters, false));
 }