private void GetControllers(IList <ControllerObject> classes,
                                    ICollection <string> classesNames, IDictionary <string, ControllerObject> classesObjectsRegistry)
        {
            var rootController = new ControllerObject {
                Name = "Home", PrefixUri = "/"
            };

            foreach (var resource in raml.Resources)
            {
                if (resource == null)
                {
                    continue;
                }

                var fullUrl = GetUrl(string.Empty, resource.RelativeUri);

                // when the resource is a parameter dont generate a class but add it's methods and children to the parent
                if (resource.RelativeUri.StartsWith("/{") && resource.RelativeUri.EndsWith("}"))
                {
                    var generatedMethods = webApiMethodsGenerator.GetMethods(resource, fullUrl, rootController, rootController.Name, schemaResponseObjects, schemaRequestObjects);
                    foreach (var method in generatedMethods)
                    {
                        rootController.Methods.Add(method);
                    }

                    GetMethodsFromChildResources(resource.Resources, fullUrl, rootController);

                    classesNames.Add(rootController.Name);
                    classesObjectsRegistry.Add(CalculateClassKey("/"), rootController);
                    classes.Add(rootController);
                }
                else
                {
                    var controller = new ControllerObject
                    {
                        Name        = GetUniqueObjectName(resource, null),
                        PrefixUri   = UrlGeneratorHelper.FixControllerRoutePrefix(fullUrl),
                        Description = resource.Description,
                    };

                    var methods = webApiMethodsGenerator.GetMethods(resource, fullUrl, controller, controller.Name, schemaResponseObjects, schemaRequestObjects);
                    foreach (var method in methods)
                    {
                        controller.Methods.Add(method);
                    }

                    classesNames.Add(controller.Name);
                    classes.Add(controller);
                    classesObjectsRegistry.Add(CalculateClassKey(fullUrl), controller);

                    GetMethodsFromChildResources(resource.Resources, fullUrl, controller);
                }
            }
        }
Exemplo n.º 2
0
        private ControllerObject CreateControllerAndAddMethods(IList <ControllerObject> classes, ICollection <string> classesNames,
                                                               IDictionary <string, ControllerObject> classesObjectsRegistry, Resource resource, string fullUrl, IDictionary <string, Parameter> parentUriParameters)
        {
            var controller = new ControllerObject
            {
                Name        = GetUniqueObjectName(resource, null),
                PrefixUri   = UrlGeneratorHelper.FixControllerRoutePrefix(fullUrl),
                Description = resource.Description,
            };

            var methods = webApiMethodsGenerator.GetMethods(resource, fullUrl, controller, controller.Name, parentUriParameters);

            foreach (var method in methods)
            {
                controller.Methods.Add(method);
            }

            classesNames.Add(controller.Name);
            classes.Add(controller);
            classesObjectsRegistry.Add(CalculateClassKey(fullUrl), controller);
            return(controller);
        }