private string ParseEnum(string key, JsonSchema schema, IDictionary <string, ApiEnum> enums, string description)
        {
            var name = NetNamingMapper.GetObjectName(key);

            var apiEnum = new ApiEnum
            {
                Name        = name,
                Description = description,
                Values      = schema.Enum.Select(e => RamlTypeParser.ToEnumValueName(e.ToString())).ToList()
            };

            if (enums.ContainsKey(name))
            {
                if (IsAlreadyAdded(enums, apiEnum))
                {
                    return(name);
                }

                apiEnum.Name = UniquenessHelper.GetUniqueName(enums, name);
            }

            enums.Add(apiEnum.Name, apiEnum);

            return(apiEnum.Name);
        }
        private string ParseObject(string key, Newtonsoft.JsonV4.Schema.JsonSchema schema, IDictionary <string, ApiObject> objects,
                                   IDictionary <string, ApiEnum> enums, Newtonsoft.JsonV4.Schema.JsonSchema parentSchema, string baseClass = null)
        {
            var propertiesSchemas = schema.Properties;
            var obj = new ApiObject
            {
                Name       = NetNamingMapper.GetObjectName(key),
                Properties = ParseSchema(propertiesSchemas, objects, enums, parentSchema),
                BaseClass  = baseClass
            };

            AdditionalProperties(obj.Properties, schema);

            if (!obj.Properties.Any())
            {
                return(null);
            }

            // Avoid duplicated keys and names
            if (objects.ContainsKey(key) || objects.Any(o => o.Value.Name == obj.Name) ||
                otherObjects.ContainsKey(key) || otherObjects.Any(o => o.Value.Name == obj.Name) ||
                schemaObjects.ContainsKey(key) || schemaObjects.Any(o => o.Value.Name == obj.Name))
            {
                if (UniquenessHelper.HasSameProperties(obj, objects, key, otherObjects, schemaObjects))
                {
                    return(key);
                }

                obj.Name = UniquenessHelper.GetUniqueName(objects, obj.Name, otherObjects, schemaObjects);
                key      = UniquenessHelper.GetUniqueKey(objects, key, otherObjects);
            }

            objects.Add(key, obj);
            return(key);
        }
        private void ParseProperties(IDictionary <string, ApiObject> objects, ICollection <Property> props, IDictionary <string, JsonSchema> properties, IDictionary <string, ApiEnum> enums)
        {
            if (properties == null)
            {
                return;
            }

            foreach (var property in properties)
            {
                if ((property.Value.Enum != null && !property.Value.Enum.Any()) && (property.Value.Type == null || property.Value.Type == JsonSchemaType.Null ||
                                                                                    property.Value.Type == JsonSchemaType.None))
                {
                    continue;
                }

                var key = property.Key;
                if (string.IsNullOrWhiteSpace(key))
                {
                    key = UniquenessHelper.GetUniqueName(props);
                }

                var isEnum = property.Value.Enum != null && property.Value.Enum.Any();

                var enumName = string.Empty;
                if (isEnum)
                {
                    enumName = ParseEnum(key, property.Value, enums, property.Value.Description);
                }

                var type = GetType(property, isEnum, enumName);
                if (type == null)
                {
                    continue;
                }

                var prop = CreateProperty(key, type, property, isEnum);


                ParseComplexTypes(objects, property.Value, prop, property, key, enums);
                props.Add(prop);

                AdditionalProperties(props, property.Value);
            }
        }
        private string ParseObject(string key, IDictionary <string, JsonSchema> schema, IDictionary <string, ApiObject> objects, IDictionary <string, ApiEnum> enums)
        {
            if (schema == null)
            {
                return(null);
            }

            var obj = new ApiObject
            {
                Name       = NetNamingMapper.GetObjectName(key),
                Properties = ParseSchema(schema, objects, enums)
            };

            if (obj == null)
            {
                return(null);
            }

            if (!obj.Properties.Any())
            {
                return(null);
            }

            // Avoid duplicated keys and names or no properties
            if (objects.ContainsKey(key) || objects.Any(o => o.Value.Name == obj.Name) ||
                otherObjects.ContainsKey(key) || otherObjects.Any(o => o.Value.Name == obj.Name) ||
                schemaObjects.ContainsKey(key) || schemaObjects.Any(o => o.Value.Name == obj.Name))
            {
                if (UniquenessHelper.HasSameProperties(obj, objects, key, otherObjects, schemaObjects))
                {
                    return(key);
                }

                obj.Name = UniquenessHelper.GetUniqueName(objects, obj.Name, otherObjects, schemaObjects);
                key      = UniquenessHelper.GetUniqueKey(objects, key, otherObjects);
            }

            objects.Add(key, obj);
            return(key);
        }