示例#1
0
        private void AddGeneratedMethod(AMF.Parser.Model.EndPoint resource, string url, string objectName, Operation method, ICollection <string> methodsNames,
                                        ICollection <ClientGeneratorMethod> generatorMethods, IDictionary <string, Parameter> parentUriParameters, string modelsNamespace)
        {
            var generatedMethod = BuildClassMethod(url, method, resource, modelsNamespace);

            if (generatedMethod.ReturnType != "string")
            {
                var returnType = CollectionTypeHelper.GetBaseType(generatedMethod.ReturnType);

                var returnTypeObject = schemaObjects.Values.Any(o => o.Name == returnType)
                    ? schemaObjects.Values.First(o => o.Name == returnType)
                    : schemaResponseObjects.Values.FirstOrDefault(o => o.Name == returnType);

                if (returnTypeObject != null)
                {
                    generatedMethod.ReturnTypeObject = returnTypeObject;
                    generatedMethod.OkReturnType     = GetOkReturnType(generatedMethod);
                }
            }
            uriParametersGenerator.Generate(resource, url, generatedMethod, uriParameterObjects, parentUriParameters);

            if (!IsVerbForMethod(method))
            {
                return;
            }

            if (methodsNames.Contains(generatedMethod.Name))
            {
                generatedMethod.Name = GetUniqueName(methodsNames, generatedMethod.Name, resource.Path);
            }

            GetQueryParameters(objectName, method, generatedMethod);

            GetHeaders(objectName, method, generatedMethod);

            GetResponseHeaders(objectName, generatedMethod, method);

            generatorMethods.Add(generatedMethod);
            methodsNames.Add(generatedMethod.Name);
        }
示例#2
0
        private ClientGeneratorMethod BuildClassMethod(string url, Operation operation, AMF.Parser.Model.EndPoint resource, string modelsNamespace)
        {
            var parentUrl = UrlGeneratorHelper.GetParentUri(url, resource.Path);

            //TODO: check
            var responseContentTypes = operation.Responses != null?
                                       operation.Responses.Where(r => r.Payloads != null).SelectMany(r => r.Payloads).Select(p => p.MediaType).ToArray()
                                           : new string[0];

            var generatedMethod = new ClientGeneratorMethod
            {
                ModelsNamespace      = modelsNamespace,
                Name                 = NetNamingMapper.GetMethodName(operation.Method ?? "Get" + resource.Path),
                ReturnType           = GetReturnType(operation, resource, url),
                Parameter            = GetParameter(GeneratorServiceHelper.GetKeyForResource(operation, resource), operation, resource, url),
                Comment              = GetComment(resource, operation, url),
                Url                  = url,
                Verb                 = NetNamingMapper.Capitalize(operation.Method),
                Parent               = null,
                UseSecurity          = resource.Operations.Any(m => m.Method == operation.Method && m.Security != null && m.Security.Any()),
                RequestContentTypes  = operation.ContentType,
                ResponseContentTypes = responseContentTypes
            };

            // look in traits

            // look in resource types

            return(generatedMethod);
        }