Пример #1
0
        public List <OutputService> GetServices(Document document, List <BaseOutputClass> baseOutputClasses)
        {
            var services = new Dictionary <string, OutputService>();

            foreach (var path in document.Paths)
            {
                var servicePath = path.Key;
                foreach (var action in path.Value)
                {
                    var method      = action.Key;
                    var actionValue = action.Value;
                    var tag         = actionValue.Tags[0];
                    if (!services.ContainsKey(tag))
                    {
                        var newService = new OutputService()
                        {
                            Name = tag
                        };
                        services.Add(tag, newService);
                    }
                    var service      = services[tag];
                    var outputAction = new OutputServiceAction()
                    {
                        Method      = OutputServiceAction.ParseMethodType(method),
                        Path        = servicePath,
                        RequestBody = OutputServiceAction.ParseRequestBody(actionValue.RequestBody, baseOutputClasses),
                        Responses   = OutputServiceAction.ParseResponses(actionValue.Responses, baseOutputClasses),
                        Parameters  = OutputServiceAction.ParseParameters(actionValue.Parameters, baseOutputClasses)
                    };
                    service.Actions.Add(outputAction);
                }
            }
            return(services.Values.ToList());
        }
Пример #2
0
        private string GetMethodName(List <OutputServiceAction> list, OutputServiceAction current)
        {
            var count = list.Count(p => p.Method == current.Method);

            if (count == 1)
            {
                return(current.AngularMethod);
            }
            if (count == 2 && current.Method == MethodTypeEnum.Get)
            {
                var other = list.FirstOrDefault(p => p.Method == current.Method && p.Path != current.Path);

                if (current.PathChunks.Count(p => p.IsParameter) == 0 && other.PathChunks.Count(p => p.IsParameter) != 0)
                {
                    return("getAll");
                }
                if (current.PathChunks.Count(p => p.IsParameter) == 1 && other.PathChunks.Count(p => p.IsParameter) != 1)
                {
                    return("get");
                }
            }
            return(current.AngularMethod);
        }