private void AddProperty(Resource resource, Method method, string key, Response response, ICollection <Property> properties, string fullUrl)
        {
            var mimeType = GeneratorServiceHelper.GetMimeType(response);

            if (mimeType == null)
            {
                return;
            }

            var type = GetReturnTypeFromResponse(method, resource, mimeType, key, response.Code, fullUrl);

            if (string.IsNullOrWhiteSpace(type))
            {
                return;
            }

            var property = new Property
            {
                Name        = CollectionTypeHelper.GetBaseType(type),
                Description = response.Description + " " + mimeType.Description,
                Example     = mimeType.Example,
                Type        = type,
                StatusCode  = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), response.Code),
                JSONSchema  = mimeType.Schema == null ? null : mimeType.Schema.Replace(Environment.NewLine, "").Replace("\r\n", "").Replace("\n", "").Replace("\"", "\\\"")
            };

            properties.Add(property);
        }
        private string GetReturnTypeFromResourceType(Method method, Resource resource, string key, string responseCode, string fullUrl)
        {
            var returnType = string.Empty;

            if (resource.Type == null || !resource.Type.Any() ||
                !raml.ResourceTypes.Any(rt => rt.ContainsKey(resource.GetResourceType())))
            {
                return(returnType);
            }

            var verb = GetResourceTypeVerb(method, resource);

            if (verb == null || verb.Responses == null ||
                !verb.Responses.Any(r => r != null && r.Body != null &&
                                    r.Body.Values.Any(m => !string.IsNullOrWhiteSpace(m.Schema))))
            {
                return(returnType);
            }

            var response = verb.Responses.FirstOrDefault(r => r.Code == responseCode);

            if (response == null)
            {
                return(returnType);
            }

            var resourceTypeMimeType = GeneratorServiceHelper.GetMimeType(response);

            if (resourceTypeMimeType != null)
            {
                returnType = GetReturnTypeFromResponseWithoutCheckingResourceTypes(method, resource, resourceTypeMimeType, key, responseCode, fullUrl);
            }
            return(returnType);
        }
        private void ParseResponses(IDictionary <string, ApiObject> objects, KeyValuePair <string, ResourceType> type, Verb verb)
        {
            if (verb.Responses == null)
            {
                return;
            }

            foreach (var response in verb.Responses.Where(response => response != null))
            {
                var name = Enum.GetName(typeof(VerbType), verb.Type);
                if (name == null)
                {
                    continue;
                }

                var key = type.Key + "-" + name.ToLower() + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;

                if (response.Body == null || !response.Body.Any(b => b.Value != null && !string.IsNullOrWhiteSpace(b.Value.Schema)))
                {
                    continue;
                }

                var mimeType = GeneratorServiceHelper.GetMimeType(response);

                var obj = objectParser.ParseObject(key, mimeType.Schema, objects, warnings);
                // Avoid duplicated keys and names
                if (obj != null && !objects.ContainsKey(key) && objects.All(o => o.Value.Name != obj.Name) && obj.Properties.Any())
                {
                    objects.Add(key, obj);
                }
            }
        }
Пример #4
0
        private void ParseResponses(KeyValuePair <string, ResourceType> type, Verb verb)
        {
            if (verb.Responses == null)
            {
                return;
            }

            foreach (var response in verb.Responses.Where(response => response != null))
            {
                var name = Enum.GetName(typeof(VerbType), verb.Type);
                if (name == null)
                {
                    continue;
                }

                var key = type.Key + "-" + name.ToLower() + ParserHelpers.GetStatusCode(response.Code) + ResponseContentSuffix;

                if (response.Body == null || !response.Body.Any(b => b.Value != null && !string.IsNullOrWhiteSpace(b.Value.Schema)))
                {
                    continue;
                }

                var mimeType = GeneratorServiceHelper.GetMimeType(response);

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

                AddObjectToObjectCollectionOrLink(obj, key, schemaResponseObjects, schemaObjects);
            }
        }
        private void AddProperty(Resource resource, Method method, string key, IDictionary <string, ApiObject> schemaResponseObjects,
                                 Response response, List <Property> properties)
        {
            var mimeType = GeneratorServiceHelper.GetMimeType(response);

            if (mimeType == null)
            {
                return;
            }

            var type = GetReturnTypeFromResponse(method, resource, mimeType, key, response.Code, schemaResponseObjects);

            if (string.IsNullOrWhiteSpace(type))
            {
                return;
            }

            var property = new Property
            {
                Name        = type.Replace("[]", string.Empty),
                Description = response.Description + " " + mimeType.Description,
                Example     = mimeType.Example,
                Type        = type,
                StatusCode  = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), response.Code)
            };

            properties.Add(property);
        }