Esempio n. 1
0
        private void ParseResourceResponsesRecursively(IEnumerable <Resource> resources, string fullUrl)
        {
            foreach (var resource in resources)
            {
                if (resource.Methods != null)
                {
                    foreach (var method in resource.Methods.Where(m => m.Responses != null && m.Responses.Any()))
                    {
                        foreach (var response in method.Responses.Where(r => r.Body != null && r.Body.Any()))
                        {
                            foreach (var kv in response.Body.Where(b => b.Value.Schema != null))
                            {
                                var key = GeneratorServiceHelper.GetKeyForResource(method, resource, fullUrl) + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;
                                if (schemaResponseObjects.ContainsKey(key))
                                {
                                    continue;
                                }

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

                                AddObjectToObjectCollectionOrLink(obj, key, schemaResponseObjects, schemaObjects);
                            }

                            foreach (var kv in response.Body.Where(b => b.Value.InlineType != null))
                            {
                                var key = GeneratorServiceHelper.GetKeyForResource(method, resource, fullUrl) + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;
                                if (schemaResponseObjects.ContainsKey(key))
                                {
                                    continue;
                                }

                                var obj = raml1TypesParser.ParseInline(key, kv.Value.InlineType, schemaResponseObjects);

                                AddObjectToObjectCollectionOrLink(obj, key, schemaResponseObjects, schemaObjects);
                            }
                        }
                    }
                }
                if (resource.Resources != null)
                {
                    ParseResourceResponsesRecursively(resource.Resources, fullUrl + resource.RelativeUri);
                }
            }
        }
        private void ParseResourceResponsesRecursively(IDictionary <string, ApiObject> objects, IEnumerable <Resource> resources)
        {
            foreach (var resource in resources)
            {
                if (resource.Methods != null)
                {
                    foreach (var method in resource.Methods.Where(m => m.Responses != null && m.Responses.Any()))
                    {
                        foreach (var response in method.Responses.Where(r => r.Body != null && r.Body.Any()))
                        {
                            foreach (var kv in response.Body.Where(b => b.Value.Schema != null))
                            {
                                var key = GeneratorServiceHelper.GetKeyForResource(method, resource) + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;
                                if (objects.ContainsKey(key))
                                {
                                    continue;
                                }

                                var obj = objectParser.ParseObject(key, kv.Value.Schema, objects, warnings);

                                // Avoid duplicated names and objects without properties
                                if (obj != null && objects.All(o => o.Value.Name != obj.Name) && obj.Properties.Any())
                                {
                                    objects.Add(key, obj);
                                }
                            }
                        }
                    }
                }
                if (resource.Resources != null)
                {
                    ParseResourceResponsesRecursively(objects, resource.Resources);
                }
            }
        }