Ejemplo n.º 1
0
        private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription)
        {
            if (!apiDescription.ParameterDescriptions.Any())
            {
                return;
            }

            var matchedMethodParamNames = ArrayMatcher.Match(
                apiDescription.ParameterDescriptions.Select(p => p.Name).ToArray(),
                method.GetParameters().Select(GetMethodParamName).ToArray()
                );

            for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++)
            {
                var parameterDescription   = apiDescription.ParameterDescriptions[i];
                var matchedMethodParamName = matchedMethodParamNames.Length > i
                                                 ? matchedMethodParamNames[i]
                                                 : parameterDescription.Name;

                actionModel.AddParameter(ParameterApiDescriptionModel.Create(
                                             parameterDescription.Name,
                                             matchedMethodParamName,
                                             parameterDescription.Type,
                                             parameterDescription.RouteInfo?.IsOptional ?? false,
                                             parameterDescription.RouteInfo?.DefaultValue,
                                             parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(),
                                             parameterDescription.Source.Id,
                                             parameterDescription.ModelMetadata?.ContainerType != null
                            ? parameterDescription.ParameterDescriptor?.Name ?? string.Empty
                            : string.Empty
                                             )
                                         );
            }
        }
Ejemplo n.º 2
0
    public static string GetFormPostParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo)
    {
        var parameterInfoName = string.Join(".", parameterInfo.Name.Split(".").Select(x => NormalizeJsVariableName(x.ToCamelCase())));

        return(parameterInfo.Name == parameterInfo.NameOnMethod
            ? parameterInfoName
            : NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + parameterInfoName);
    }
 public static string GetParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo)
 {
     return(parameterInfo.Name == parameterInfo.NameOnMethod
                ? NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), ".")
                : NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), "."));
 }
Ejemplo n.º 4
0
        public static object FindParameterValue(IReadOnlyDictionary <string, object> methodArguments, ParameterApiDescriptionModel apiParameter)
        {
            var value = methodArguments.GetOrDefault(apiParameter.NameOnMethod);

            if (value == null)
            {
                return(null);
            }

            if (apiParameter.Name == apiParameter.NameOnMethod)
            {
                return(value);
            }

            return(ReflectionHelper.GetValueByPath(value, value.GetType(), apiParameter.Name));
        }
 protected virtual async Task <List <KeyValuePair <string, HttpContent> > > ObjectToFormDataAsync <T>(IObjectToFormData <T> converter, ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, T value)
 {
     return(await converter.ConvertAsync(actionApiDescription, parameterApiDescription, value));
 }
Ejemplo n.º 6
0
 protected virtual async Task <string> ObjectToPathAsync <T>(IObjectToPath <T> converter, ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, T value)
 {
     return(await converter.ConvertAsync(actionApiDescription, parameterApiDescription, value));
 }
Ejemplo n.º 7
0
    public Task <List <KeyValuePair <string, HttpContent> > > ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, List <GetParamsNameValue> values)
    {
        if (values.IsNullOrEmpty())
        {
            return(null);
        }

        var formDataContents = new List <KeyValuePair <string, HttpContent> >();

        for (var i = 0; i < values.Count; i++)
        {
            formDataContents.Add(new KeyValuePair <string, HttpContent>($"NameValues[{i}].Name", new StringContent(values[i].Name, Encoding.UTF8)));
            formDataContents.Add(new KeyValuePair <string, HttpContent>($"NameValues[{i}].Value", new StringContent(values[i].Value, Encoding.UTF8)));
        }

        return(Task.FromResult(formDataContents));
    }
Ejemplo n.º 8
0
 public ParameterApiDescriptionModel AddParameter(ParameterApiDescriptionModel parameter)
 {
     Parameters.Add(parameter);
     return(parameter);
 }
Ejemplo n.º 9
0
    public Task <string> ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, List <GetParamsNameValue> values)
    {
        if (values.IsNullOrEmpty())
        {
            return(null);
        }

        var sb = new StringBuilder();

        for (var i = 0; i < values.Count; i++)
        {
            sb.Append($"NameValues[{i}].Name={values[i].Name}&NameValues[{i}].Value={values[i].Value}&");
        }

        sb.Remove(sb.Length - 1, 1);
        return(Task.FromResult(sb.ToString()));
    }
Ejemplo n.º 10
0
    public Task <string> ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, int value)
    {
        if (actionApiDescription.Name == nameof(IRegularTestController.GetObjectandCountAsync))
        {
            if (value <= 0)
            {
                value = 888;
            }
            return(Task.FromResult(value.ToString()));
        }

        return(Task.FromResult <string>(null));
    }