Esempio n. 1
0
        private void AddObjectToObjectCollectionOrLink(ApiObject obj, string key, IDictionary <string, ApiObject> objects, IDictionary <string, ApiObject> otherObjects)
        {
            if (obj == null || (!obj.Properties.Any() && obj.Type == null))
            {
                return;
            }

            if (schemaObjects.All(o => o.Value.Name != obj.Name) && objects.All(o => o.Value.Name != obj.Name) && otherObjects.All(o => o.Value.Name != obj.Name))
            {
                objects.Add(key, obj);
            }
            else
            {
                if (UniquenessHelper.HasSameProperties(obj, objects, key, otherObjects, schemaObjects))
                {
                    if (string.IsNullOrWhiteSpace(obj.GeneratedCode) && !linkKeysWithObjectNames.ContainsKey(key))
                    {
                        linkKeysWithObjectNames.Add(key, obj.Name);
                    }
                }
                else if (!objects.ContainsKey(key))
                {
                    obj.Name = UniquenessHelper.GetUniqueName(objects, obj.Name, schemaObjects, schemaObjects);
                    objects.Add(key, obj);
                }
            }
        }
Esempio n. 2
0
        private ApiObject ParseXmlSchema(string key, string schema, IDictionary <string, ApiObject> objects, string targetNamespace, IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects)
        {
            if (objects.ContainsKey(key))
            {
                return(null);
            }

            var xmlSchemaParser = new XmlSchemaParser();
            var obj             = xmlSchemaParser.Parse(key, schema, objects, targetNamespace);

            if (obj != null && !objects.ContainsKey(key) && !UniquenessHelper.HasSameProperties(obj, objects, otherObjects, schemaObjects))
            {
                objects.Add(key, obj);         // to associate that key with the main XML Schema object
            }
            return(obj);
        }
Esempio n. 3
0
        protected void ParseSchemas()
        {
            foreach (var schema in raml.Schemas)
            {
                foreach (var kv in schema)
                {
                    var key = kv.Key;

                    var obj = objectParser.ParseObject(key, kv.Value, schemaObjects, warnings, enums, new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>(), targetNamespace);

                    if (schemaObjects.ContainsKey(key))
                    {
                        if (UniquenessHelper.HasSameProperties(schemaObjects[key], schemaObjects, key,
                                                               new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>()))
                        {
                            continue;
                        }

                        var apiObject = schemaObjects[key];
                        var oldName   = apiObject.Name;
                        apiObject.Name = UniquenessHelper.GetUniqueName(schemaObjects, apiObject.Name, new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>());
                        key            = UniquenessHelper.GetUniqueKey(schemaObjects, key, new Dictionary <string, ApiObject>());
                        schemaObjects.Add(key, apiObject);
                        schemaObjects.Remove(schemaObjects.First(o => o.Key == key));
                        foreach (var apiObj in schemaObjects)
                        {
                            foreach (var prop in apiObj.Value.Properties)
                            {
                                if (prop.Type == oldName)
                                {
                                    prop.Type = apiObject.Name;
                                }
                            }
                        }
                    }
                    schemaObjects.Add(key, obj);
                }
            }
        }
        private ApiObject ParseArray(string key, RamlType ramlType)
        {
            var typeOfArray = GetTypeOfArray(key, ramlType);

            var baseType = CollectionTypeHelper.GetBaseType(typeOfArray);

            if (!NetTypeMapper.IsPrimitiveType(baseType) &&
                ramlType.Array.Items != null && ramlType.Array.Items.Type == "object")
            {
                if (baseType == typeOfArray)
                {
                    baseType = typeOfArray + "Item";
                }

                baseType = NetNamingMapper.GetObjectName(baseType);

                var itemType = ParseNestedType(ramlType.Array.Items, baseType);
                if (schemaObjects.ContainsKey(baseType) && !UniquenessHelper.HasSameProperties(itemType, schemaObjects, baseType, emptyDic, emptyDic))
                {
                    baseType      = UniquenessHelper.GetUniqueName(schemaObjects, baseType, emptyDic, emptyDic);
                    itemType.Name = baseType;
                }
                if (!schemaObjects.ContainsKey(baseType))
                {
                    schemaObjects.Add(baseType, itemType);
                }

                typeOfArray = CollectionTypeHelper.GetCollectionType(baseType);
            }

            return(new ApiObject
            {
                IsArray = true,
                Name = NetNamingMapper.GetObjectName(key),
                Description = ramlType.Description,
                Example = ramlType.Example,
                Type = typeOfArray
            });
        }
Esempio n. 5
0
        public ApiObject ParseObject(string key, string value, IDictionary <string, ApiObject> objects, IDictionary <string, string> warnings, IDictionary <string, ApiEnum> enums, IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects, string targetNamespace)
        {
            var obj = ParseSchema(key, value, objects, warnings, enums, otherObjects, schemaObjects, targetNamespace);

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

            obj.Name = NetNamingMapper.GetObjectName(key);

            if (schemaObjects.Values.Any(o => o.Name == obj.Name) || objects.Values.Any(o => o.Name == obj.Name) ||
                otherObjects.Values.Any(o => o.Name == obj.Name))
            {
                if (UniquenessHelper.HasSameProperties(obj, objects, key, otherObjects, schemaObjects))
                {
                    return(null);
                }

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

            return(obj);
        }
        private IList <Property> GetProperties(IDictionary <string, RamlType> properties, string className)
        {
            var props = new List <Property>();

            foreach (var kv in properties)
            {
                var prop = kv.Value;
                if (prop.Scalar != null)
                {
                    var newProp = GetPropertyFromScalar(prop, kv, className);
                    props.Add(newProp);
                    continue;
                }
                if (prop.Object != null)
                {
                    var name = NetNamingMapper.GetPropertyName(kv.Key);
                    if (!schemaObjects.ContainsKey(name) && !schemaObjects.ContainsKey(prop.Type))
                    {
                        var newApiObject = GetApiObjectFromObject(prop, name);
                        if (schemaObjects.ContainsKey(name) && !UniquenessHelper.HasSameProperties(newApiObject, schemaObjects, name, emptyDic, emptyDic))
                        {
                            name = UniquenessHelper.GetUniqueName(schemaObjects, name, emptyDic, emptyDic);
                            newApiObject.Name = name;
                        }
                        if (!schemaObjects.ContainsKey(name))
                        {
                            schemaObjects.Add(name, newApiObject);
                        }
                        props.Add(new Property(className)
                        {
                            Name = name, Type = name, Required = prop.Required, OriginalName = kv.Key.TrimEnd('?')
                        });
                    }
                    else
                    {
                        ApiObject apiObject;
                        if (schemaObjects.ContainsKey(prop.Type))
                        {
                            apiObject = schemaObjects[prop.Type];
                        }
                        else
                        {
                            apiObject = schemaObjects[name];
                        }

                        props.Add(new Property(className)
                        {
                            Name = name, Type = apiObject.Name, Required = prop.Required, OriginalName = kv.Key.TrimEnd('?')
                        });
                    }

                    continue;
                }
                if (prop.Array != null)
                {
                    var name = NetNamingMapper.GetPropertyName(kv.Key);
                    var type = kv.Value.Type;
                    if (kv.Value.Array.Items != null)
                    {
                        if (kv.Value.Array.Items.Object == null && NetTypeMapper.IsPrimitiveType(kv.Value.Array.Items.Type))
                        {
                            type = CollectionTypeHelper.GetCollectionType(NetTypeMapper.Map(kv.Value.Array.Items.Type));
                        }
                        else
                        {
                            var obj = ParseArray(kv.Key, kv.Value);
                            // type = CollectionTypeHelper.GetCollectionType(obj.Type);
                            type = obj.Type;
                        }
                    }
                    if (type.EndsWith("[]"))
                    {
                        type = type.Substring(0, type.Length - 2);
                        if (!NetTypeMapper.IsPrimitiveType(type))
                        {
                            type = NetNamingMapper.GetObjectName(type);
                        }

                        type = CollectionTypeHelper.GetCollectionType(type);
                    }

                    props.Add(new Property(className)
                    {
                        Name = name, Type = type, Required = prop.Required, OriginalName = kv.Key.TrimEnd('?')
                    });
                }
                if (!string.IsNullOrWhiteSpace(prop.Type))
                {
                    var newProp = new Property(className)
                    {
                        Type         = NetNamingMapper.GetObjectName(kv.Key),
                        Name         = NetNamingMapper.GetPropertyName(kv.Key),
                        Required     = prop.Required,
                        Example      = prop.Example,
                        Description  = prop.Description,
                        OriginalName = kv.Key.TrimEnd('?')
                    };
                    props.Add(newProp);
                    continue;
                }
            }
            return(props);
        }