private static void ApplyToMethods(IEnumerable <IDictionary <string, ResourceType> > resourceTypes, ICollection <Method> methods, string type,
                                           IEnumerable <IDictionary <string, Method> > traits, string defaultMediaType)
        {
            if (type == null || !resourceTypes.Any(t => t.ContainsKey(type)))
            {
                return;
            }

            var resourceType = resourceTypes.First(t => t.ContainsKey(type))[type];

            // handle traits
            TraitsApplier.ApplyTraitsToMethods(methods, traits, resourceType.Is);

            AddOrApplyToMethod(methods, "get", resourceType.Get, defaultMediaType);

            AddOrApplyToMethod(methods, "delete", resourceType.Delete, defaultMediaType);

            AddOrApplyToMethod(methods, "options", resourceType.Options, defaultMediaType);

            AddOrApplyToMethod(methods, "patch", resourceType.Patch, defaultMediaType);

            AddOrApplyToMethod(methods, "post", resourceType.Post, defaultMediaType);

            AddOrApplyToMethod(methods, "put", resourceType.Put, defaultMediaType);

            // handle nested resource type
            ApplyToMethods(resourceTypes, methods, resourceType.Type, traits, defaultMediaType);
        }
Beispiel #2
0
        private void ApplyResourceTypesAndTraits(ICollection <Resource> resources)
        {
            foreach (var resource in resources)
            {
                var methods = resource.Methods.ToList();

                ResourceTypeApplier.Apply(raml.ResourceTypes, GetResourceType(resource.Type), methods, raml.Traits, resource,
                                          raml.MediaType);

                if (resource.Is != null && resource.Is.Any())
                {
                    TraitsApplier.ApplyTraitsToMethods(methods, raml.Traits, resource.Is);
                }

                foreach (var method in methods.Where(method => method.Is != null))
                {
                    TraitsApplier.ApplyTraitsToMethod(method, raml.Traits, method.Is);
                }

                resource.Methods = methods;
                ApplyResourceTypesAndTraits(resource.Resources);
            }
        }