Exemple #1
0
 public StandardFluentMethod(MethodJvaf innerMethod, IFluentMethodGroup methodGroup)
 {
     if (!CanWrap(innerMethod))
     {
         throw new ArgumentException($"StandardFluentMethod can wrap only inner methods that return wrappable return type, received inner method '{innerMethod.ReturnTypeResponseName} {innerMethod.Name}(..)'");
     }
     //
     this.InnerMethod       = innerMethod;
     this.FluentMethodGroup = methodGroup;
 }
        private string InnerMethodInvocationParameter(MethodJvaf innerMethod)
        {
            List <string> invoke = new List <string>();

            foreach (var parameter in innerMethod.LocalParameters.Where(p => !p.IsConstant && p.IsRequired))
            {
                invoke.Add(parameter.Name);
            }

            return(string.Join(", ", invoke));
        }
Exemple #3
0
 public static bool CanWrap(MethodJvaf innerMethod)
 {
     if (innerMethod.HttpMethod == HttpMethod.Delete)
     {
         return(true);
     }
     else
     {
         return(innerMethod.HasWrappableReturnType());
     }
 }
        private static MethodType GetMethodType(MethodJvaf method)
        {
            Regex leading   = new Regex("^/+");
            Regex trailing  = new Regex("/+$");
            var   methodUrl = trailing.Replace(leading.Replace(method.Url, ""), "");

            if (method.HttpMethod == HttpMethod.Get)
            {
                var urlSplits = methodUrl.Split('/');
                if ((urlSplits.Count() == 5 || urlSplits.Count() == 7) &&
                    StringComparer.OrdinalIgnoreCase.Equals(urlSplits[0], "subscriptions") &&
                    HasSequenceType(method.ReturnType.Body))
                {
                    if (urlSplits.Count() == 5)
                    {
                        if (StringComparer.OrdinalIgnoreCase.Equals(urlSplits[2], "providers"))
                        {
                            return(MethodType.ListBySubscription);
                        }
                        else
                        {
                            return(MethodType.ListByResourceGroup);
                        }
                    }
                    else if (StringComparer.OrdinalIgnoreCase.Equals(urlSplits[2], "resourceGroups"))
                    {
                        return(MethodType.ListByResourceGroup);
                    }
                }
                if (IsTopLevelResourceUrl(methodUrl))
                {
                    return(MethodType.Get);
                }
            }
            else if (method.HttpMethod == HttpMethod.Delete)
            {
                if (method.Name.Value.ToLowerInvariant().StartsWith("begin") ||
                    method.MethodGroup.Methods.Count(x => x.HttpMethod == HttpMethod.Delete) > 1)
                {
                    return(MethodType.Other);
                }

                if (IsTopLevelResourceUrl(methodUrl))
                {
                    return(MethodType.Delete);
                }
            }

            return(MethodType.Other);
        }
 public FluentMethod(bool isStandard, MethodJvaf innerMethod, FluentMethodGroup methodGroup)
 {
     this.isStandard  = isStandard;
     this.InnerMethod = innerMethod;
     this.MethodGroup = methodGroup;
 }
Exemple #6
0
 /// <summary>
 /// Creates an ARMUri instance representing uri to an api call.
 /// </summary>
 /// <param name="method">the api method</param>
 public ARMUri(MethodJvaf method)
 {
     this.method = method;
     this.rawUrl = this.FluentConfig.MappedUrl(method.Url);
     this.Init();
 }
 public OtherMethod(MethodJvaf innerMethod, IFluentMethodGroup methodGroup)
 {
     this.InnerMethod       = innerMethod;
     this.FluentMethodGroup = methodGroup;
 }
Exemple #8
0
 public ARMUri(MethodJvaf method)
 {
     this.method = method;
     this.rawUrl = method.Url;
     this.Init();
 }
        /// <summary>
        /// Given an ARM operation endpoint Uri, derive a "Segment Fluent Method Group" that the operation can possibly belongs to.
        /// </summary>
        /// <param name="fluentMethodGroups">the map holding all "Segment Fluent Method Group"s</param>
        /// <param name="innerMethod">inner Swagger method</param>
        /// <param name="segments">the ARM operation endpoint uri segments those appear after Provider name</param>
        /// <returns>The segment fluent method group</returns>
        public static SegmentFluentMethodGroup ResolveFluentMethodGroup(SegmentFluentMethodGroups fluentMethodGroups,
                                                                        MethodJvaf innerMethod,
                                                                        IEnumerable <Segment> segments,
                                                                        string defaultMethodGroupName)
        {
            List <string> fluentMethodGroupNamesInSegments = new List <string>();
            Pluralizer    pluralizer = new Pluralizer();
            HttpMethod    httpMethod = innerMethod.HttpMethod;

            segments
            .Where(segment => !(segment is PositionalSegment) && Utils.IsPlural(segment.Name, fluentMethodGroups.FluentConfig))
            .ForEach(segment =>
            {
                fluentMethodGroupNamesInSegments.Add(segment.Name);
            });
            //
            if (fluentMethodGroupNamesInSegments.Count() == 0)
            {
                // Level 0 "Fluent Method Group"
                return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                    localName: defaultMethodGroupName,
                                                    parentMethodGroupNames: new List <string>()));
            }
            if (fluentMethodGroupNamesInSegments.Count() == 1)
            {
                // Level 0 "Fluent Method Group"
                return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                    localName: fluentMethodGroupNamesInSegments[0],
                                                    parentMethodGroupNames: new List <string>()));
            }
            else if (httpMethod == HttpMethod.Post)
            {
                if (segments.Last() is TerminalSegment &&
                    segments.Last().Name.EqualsIgnoreCase(fluentMethodGroupNamesInSegments.Last()))
                {
                    //POST /providers/Microsoft.EventHub/namespaces/{nsname}/authorizationRules/{ruleName}/listKeys
                    //
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.SkipLast(1).Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(2).ToList()));
                }
                else
                {
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(1).ToList()));
                }
            }
            else
            {
                IModelTypeJv retType = innerMethod.ReturnTypeJva.BodyClientType;
                if ((httpMethod == HttpMethod.Get || httpMethod == HttpMethod.Put) &&
                    (retType is PrimaryType || (retType as SequenceType)?.ElementType is PrimaryType))
                {
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.SkipLast(1).Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(2).ToList()));
                }
                else
                {
                    return(new SegmentFluentMethodGroup(fluentMethodGroups: fluentMethodGroups,
                                                        localName: fluentMethodGroupNamesInSegments.Last(),
                                                        parentMethodGroupNames: fluentMethodGroupNamesInSegments.SkipLast(1).ToList()));
                }
            }
        }
 public void AddInnerMethod(MethodJvaf innerMethod)
 {
     this.innerMethods.Add(innerMethod);
 }
 private static IEnumerable <ParameterJv> RequiredParametersOfMethod(MethodJvaf method)
 {
     return(method.LocalParameters.Where(parameter => parameter.IsRequired && !parameter.IsConstant));
 }
Exemple #12
0
        private IEnumerable <string> FilteredMethodDecls(StandardMethodsInfo standardMethodsInfo)
        {
            IEnumerable <OtherMethod> otherMethods = this
                                                     .Where(o => !standardMethodsInfo.IsStandardInnerMethod(o.InnerMethod) &&
                                                            !standardMethodsInfo.IsConfictWithStandardFluentMethod(o.InnerMethod));
            //
            StringBuilder methodsBuilder = new StringBuilder();

            foreach (OtherMethod otherMethod in otherMethods)
            {
                MethodJvaf innerMethod = otherMethod.InnerMethod;
                string     methodName  = $"{innerMethod.Name.Value}Async";
                //
                string rxReturnType;
                if (otherMethod.ReturnModel is WrappableFluentModel wrappableFluentModel)
                {
                    rxReturnType = $"Observable<{wrappableFluentModel.JavaInterfaceName}>";
                }
                else if (otherMethod.ReturnModel is NonWrappableModel nonWrappableModel)
                {
                    rxReturnType = $"Observable<{nonWrappableModel.RawModelName}>";
                }
                else
                {
                    // otherMethod.ReturnModel is PrimitiveModel
                    rxReturnType = "Completable";
                }
                //
                methodsBuilder.Clear();
                //
                methodsBuilder.AppendLine($"/**");
                if (!string.IsNullOrEmpty(innerMethod.Summary))
                {
                    methodsBuilder.AppendLine($" * {innerMethod.Summary.EscapeXmlComment().Period()}");
                }
                if (!string.IsNullOrEmpty(innerMethod.Description))
                {
                    methodsBuilder.AppendLine($" * {innerMethod.Description.EscapeXmlComment().Period()}");
                }
                methodsBuilder.AppendLine($" *");
                foreach (var param in innerMethod.LocalParameters.Where(p => !p.IsConstant && p.IsRequired))
                {
                    methodsBuilder.AppendLine($" * @param {param.Name} {param.Documentation.Else("the " + param.ModelType.Name + " value").EscapeXmlComment().Trim()}");
                }
                methodsBuilder.AppendLine($" * @throws IllegalArgumentException thrown if parameters fail the validation");
                methodsBuilder.AppendLine($" * @return the observable for the request");
                methodsBuilder.AppendLine($" */");
                if (innerMethod.HttpMethod == AutoRest.Core.Model.HttpMethod.Delete)
                {
                    methodsBuilder.AppendLine($"{rxReturnType} {methodName}({innerMethod.MethodRequiredParameterDeclaration});");
                }
                else if (otherMethod.ReturnModel is PrimitiveModel)
                {
                    methodsBuilder.AppendLine($"{rxReturnType} {methodName}({innerMethod.MethodRequiredParameterDeclaration});");
                }
                else
                {
                    methodsBuilder.AppendLine($"{rxReturnType} {methodName}({innerMethod.MethodRequiredParameterDeclaration});");
                }
                //
                yield return(methodsBuilder.ToString());
            }
        }
 public bool IsConfictWithStandardFluentMethod(MethodJvaf method)
 {
     return(FluentMethodNames.Contains(method.Name.ToLowerInvariant()));
 }
 public bool IsStandardInnerMethod(MethodJvaf method)
 {
     return(InnerMethodNames.Contains(method.Name.ToLowerInvariant()));
 }
Exemple #15
0
 public Temp(MethodJvaf innerMethod)
 {
     this.innerMethod = innerMethod;
 }