Exemplo n.º 1
0
 protected GeneratorServiceBase(RamlDocument raml, string targetNamespace)
 {
     this.raml              = raml;
     this.targetNamespace   = targetNamespace;
     apiObjectsCleaner      = new ApiObjectsCleaner(schemaRequestObjects, schemaResponseObjects, schemaObjects);
     uriParametersGenerator = new UriParametersGenerator(schemaObjects);
     ApplyResourceTypesAndTraits(raml.Resources);
     raml1TypesParser = new RamlTypeParser(raml.Types, schemaObjects, targetNamespace, enums, warnings);
 }
Exemplo n.º 2
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);
                }
            }
        }