コード例 #1
0
        private static void AddServiceMethod(ref ServiceClass serviceClass, HttpVerb httpVerb, string routeUrl, SwaggerOperationObject swaggerOperationObject, string apiNameSpace, string clientNameSpace)
        {
            ServiceMethod serviceMethod = new ServiceMethod();

            if (string.IsNullOrEmpty(swaggerOperationObject.operationId))
            {
                return;
            }

            serviceMethod.Name     = swaggerOperationObject.operationId;
            serviceMethod.HttpVerb = httpVerb;
            serviceMethod.RouteUrl = routeUrl;

            var swaggerResponseObject = swaggerOperationObject.responses.FirstOrDefault(x => x.Key.Equals("200"));

            // Add the return object
            if (swaggerResponseObject.Value != null)
            {
                if (swaggerResponseObject.Value.schema != null)
                {
                    serviceMethod.Returns = TranslateCSharpType(swaggerResponseObject.Value.schema.type,
                                                                swaggerResponseObject.Value.schema.format,
                                                                swaggerResponseObject.Value.schema._ref,
                                                                swaggerResponseObject.Value.schema.items,
                                                                apiNameSpace,
                                                                clientNameSpace);
                }
            }

            if (swaggerOperationObject.parameters != null)
            {
                foreach (var parameter in swaggerOperationObject.parameters)
                {
                    string CSharpType = TranslateCSharpType(parameter.type,
                                                            parameter.format,
                                                            parameter.schema != null ? parameter.schema._ref : null,
                                                            parameter.items,
                                                            apiNameSpace,
                                                            clientNameSpace);

                    serviceMethod.Parameters.Add(parameter.name.Replace(".", "_"), CSharpType);
                }
            }

            serviceClass.Methods.Add(serviceMethod);
        }
コード例 #2
0
        private static ServiceClass GetOrGenerateServiceClass(ref List <ServiceClass> serviceList, SwaggerOperationObject swaggerOperationObject)
        {
            string className = swaggerOperationObject.tags[0];

            ServiceClass serviceClass = serviceList.FirstOrDefault(x => x.NameOfClass.Equals(className));

            if (serviceClass == null)
            {
                serviceClass = new ServiceClass();

                serviceClass.NameOfClass = className;

                serviceList.Add(serviceClass);
            }

            return(serviceClass);
        }