Ejemplo n.º 1
0
        private void ParseResourceRequestsRecursively(IEnumerable <Resource> resources, string fullUrl)
        {
            foreach (var resource in resources)
            {
                if (resource.Methods != null)
                {
                    var methods = resource.Methods.Where(m => m.Body != null && m.Body.Any()).ToList();

                    foreach (var method in methods)
                    {
                        foreach (var kv in method.Body.Where(b => b.Value != null && b.Value.Schema != null))
                        {
                            var key = GeneratorServiceHelper.GetKeyForResource(method, resource, fullUrl) + RequestContentSuffix;
                            if (schemaRequestObjects.ContainsKey(key))
                            {
                                continue;
                            }

                            var obj = objectParser.ParseObject(key, kv.Value.Schema, schemaRequestObjects, warnings, enums, schemaResponseObjects, schemaObjects, targetNamespace);

                            AddObjectToObjectCollectionOrLink(obj, key, schemaRequestObjects, schemaObjects);
                        }
                        foreach (var kv in method.Body.Where(b => b.Value != null && b.Value.InlineType != null))
                        {
                            var key = GeneratorServiceHelper.GetKeyForResource(method, resource, fullUrl) + RequestContentSuffix;
                            if (schemaRequestObjects.ContainsKey(key))
                            {
                                continue;
                            }

                            raml1TypesParser = new RamlTypeParser(raml.Types, schemaObjects, targetNamespace, enums, warnings);
                            var obj = raml1TypesParser.ParseInline(key, kv.Value.InlineType, schemaRequestObjects);

                            AddObjectToObjectCollectionOrLink(obj, key, schemaRequestObjects, schemaObjects);
                        }
                    }
                }
                if (resource.Resources != null)
                {
                    ParseResourceRequestsRecursively(resource.Resources, fullUrl + resource.RelativeUri);
                }
            }
        }
Ejemplo n.º 2
0
        private ControllerMethod BuildControllerMethod(string url, Method method, Resource resource, ControllerObject parent, IDictionary <string, ApiObject> schemaResponseObjects, IDictionary <string, ApiObject> schemaRequestObjects)
        {
            var relativeUri = UrlGeneratorHelper.GetRelativeUri(url, parent.PrefixUri);

            return(new ControllerMethod
            {
                Name = NetNamingMapper.GetMethodName(method.Verb ?? "Get" + resource.RelativeUri),
                Parameter = GetParameter(GeneratorServiceHelper.GetKeyForResource(method, resource), method, resource, schemaRequestObjects),
                UriParameters = uriParametersGenerator.GetUriParameters(resource, url),
                ReturnType = GetReturnType(GeneratorServiceHelper.GetKeyForResource(method, resource), method, resource, schemaResponseObjects),
                Comment = GetComment(resource, method),
                Url = relativeUri,
                Verb = NetNamingMapper.Capitalize(method.Verb),
                Parent = null,
                UseSecurity =
                    raml.SecuredBy != null && raml.SecuredBy.Any() ||
                    resource.Methods.Any(m => m.Verb == method.Verb && m.SecuredBy != null && m.SecuredBy.Any()),
                SecurityParameters = GetSecurityParameters(raml, method)
            });
        }