Exemplo n.º 1
0
        public static string GenerateFormPostData(ActionApiDescriptionModel action, int indent = 0)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Form)
                             .ToArray();

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

            return(ProxyScriptingJsFuncHelper.CreateJsObjectLiteral(parameters, indent));
        }
Exemplo n.º 2
0
        private static string ReplacePathVariables(string url, IList <ParameterApiDescriptionModel> actionParameters)
        {
            var pathParameters = actionParameters
                                 .Where(p => p.BindingSourceId == ParameterBindingSources.Path)
                                 .ToArray();

            if (!pathParameters.Any())
            {
                return(url);
            }

            foreach (var pathParameter in pathParameters)
            {
                url = url.Replace($"{{{pathParameter.Name}}}", $"' + {ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(pathParameter)} + '");
            }

            return(url);
        }
Exemplo n.º 3
0
        public static string GenerateBody(ActionApiDescriptionModel action)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Body)
                             .ToArray();

            if (parameters.Length <= 0)
            {
                return(null);
            }

            if (parameters.Length > 1)
            {
                throw new StudioXException(
                          $"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But {action.Name} ({action.Url}) contains more than one!"
                          );
            }

            return(ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(parameters[0]));
        }
Exemplo n.º 4
0
        private static string AddQueryStringParameters(string url, IList <ParameterApiDescriptionModel> actionParameters)
        {
            var queryStringParameters = actionParameters
                                        .Where(p => p.BindingSourceId.IsIn(ParameterBindingSources.ModelBinding, ParameterBindingSources.Query))
                                        .ToArray();

            if (!queryStringParameters.Any())
            {
                return(url);
            }

            var qsBuilderParams = queryStringParameters
                                  .Select(p => $"{{ name: '{p.Name.ToCamelCase()}', value: {ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(p)} }}")
                                  .JoinAsString(", ");

            return(url + $"' + studiox.utils.buildQueryString([{qsBuilderParams}]) + '");
        }