Ejemplo n.º 1
0
        private static void TransformMethods(CodeModelGo cmg)
        {
            foreach (var mg in cmg.MethodGroups)
            {
                mg.Transform(cmg);
            }

            var wrapperTypes = new Dictionary <string, CompositeTypeGo>();

            foreach (var method in cmg.Methods.Cast <MethodGo>())
            {
                method.Transform(cmg);

                var scope = new VariableScopeProvider();
                foreach (var parameter in method.Parameters)
                {
                    parameter.Name = scope.GetVariableName(parameter.Name);
                }

                // fix up method return types
                if (method.ReturnType.Body.ShouldBeSyntheticType())
                {
                    var ctg = new CompositeTypeGo(method.ReturnType.Body);
                    if (wrapperTypes.ContainsKey(ctg.Name))
                    {
                        method.ReturnType = new Response(wrapperTypes[ctg.Name], method.ReturnType.Headers);
                    }
                    else
                    {
                        wrapperTypes.Add(ctg.Name, ctg);
                        cmg.Add(ctg);
                        method.ReturnType = new Response(ctg, method.ReturnType.Headers);
                    }
                }

                if (method.IsPageable && !method.IsNextMethod)
                {
                    // for pageable methods replace the return type with a page iterator.
                    // do this before LROs as you can have pageable operations that are
                    // long-running and for this case we want the future to return a paged type.
                    // note that we don't want to do this for the "next methods" that are
                    // defined explicitly in swagger as they will be used in lieu of
                    // generating a custom preparer so they must return the underlying type.
                    cmg.CreatePageableTypeForMethod(method);
                }

                if (method.IsLongRunningOperation())
                {
                    // for LROs we replace the return type with a future that
                    // knows how to poll for the operation's status and result
                    cmg.CreateFutureTypeForMethod(method);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the specified composite type into a page type.
        /// If the type specified is a future it will "unwrap" the page type from it.
        /// Throws if the specified type is not a future or page type.
        /// </summary>
        /// <param name="ctg">The type to convert from.</param>
        /// <returns>The type converted to a page type.</returns>
        internal static PageTypeGo UnwrapPageType(this CompositeTypeGo ctg)
        {
            PageTypeGo result;

            if (ctg is FutureTypeGo ftg)
            {
                result = ftg.ResultType.Cast <PageTypeGo>();
            }
            else if (ctg is PageTypeGo ptg)
            {
                result = ptg;
            }
            else
            {
                throw new InvalidCastException("supplied object is not a FutureTypeGo or PageTypeGo");
            }
            return(result);
        }
Ejemplo n.º 3
0
        private void TransformMethods(CodeModelGo cmg)
        {
            foreach (var mg in cmg.MethodGroups)
            {
                mg.Transform(cmg);
            }

            var wrapperTypes = new Dictionary <string, CompositeTypeGo>();

            foreach (var method in cmg.Methods)
            {
                ((MethodGo)method).Transform(cmg);

                var scope = new VariableScopeProvider();
                foreach (var parameter in method.Parameters)
                {
                    parameter.Name = scope.GetVariableName(parameter.Name);
                }

                // fix up method return types
                if (method.ReturnType.Body.ShouldBeSyntheticType())
                {
                    var ctg = new CompositeTypeGo(method.ReturnType.Body);
                    if (wrapperTypes.ContainsKey(ctg.Name))
                    {
                        method.ReturnType = new Response(wrapperTypes[ctg.Name], method.ReturnType.Headers);
                    }
                    else
                    {
                        wrapperTypes.Add(ctg.Name, ctg);
                        cmg.Add(ctg);
                        method.ReturnType = new Response(ctg, method.ReturnType.Headers);
                    }
                }
            }
        }