Ejemplo n.º 1
0
 private void UpdateObjects(ApiObject obj, ICollection <ApiObject> values)
 {
     foreach (var type in values)
     {
         foreach (var prop in type.Properties.Where(p => p.TypeId != null))
         {
             if (NeedsFixing(obj, prop))
             {
                 if (CollectionTypeHelper.IsCollection(prop.Type))
                 {
                     prop.Type = CollectionTypeHelper.GetCollectionType(obj.Name);
                 }
                 else
                 {
                     prop.Type = obj.Name;
                 }
             }
             else if (linkIdsWithTypes.ContainsKey(prop.TypeId))
             {
                 if (CollectionTypeHelper.IsCollection(prop.Type))
                 {
                     prop.Type = CollectionTypeHelper.GetCollectionType(linkIdsWithTypes[prop.TypeId]);
                 }
                 else
                 {
                     prop.Type = linkIdsWithTypes[prop.TypeId];
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        private bool IsUsedAsReferenceInAnyObject(ApiObject obj)
        {
            return(schemaObjects.SelectMany(o => o.Value.Properties).Any(x => x.Type == obj.Type ||
                                                                         x.Type == CollectionTypeHelper.GetCollectionType(obj.Type) ||
                                                                         x.Type == obj.BaseClass ||
                                                                         CollectionTypeHelper.GetCollectionType(x.Type) == obj.Type ||
                                                                         x.Type == CollectionTypeHelper.GetCollectionType(obj.BaseClass) ||
                                                                         CollectionTypeHelper.GetCollectionType(x.Type) == obj.BaseClass
                                                                         )

                   || schemaObjects.Values.Any(o => o.BaseClass == obj.Type)

                   || schemaRequestObjects.SelectMany(o => o.Value.Properties).Any(x => x.Type == obj.Type ||
                                                                                   x.Type == CollectionTypeHelper.GetCollectionType(obj.Type) ||
                                                                                   x.Type == obj.BaseClass ||
                                                                                   CollectionTypeHelper.GetCollectionType(x.Type) == obj.Type ||
                                                                                   x.Type == CollectionTypeHelper.GetCollectionType(obj.BaseClass) ||
                                                                                   CollectionTypeHelper.GetCollectionType(x.Type) == obj.BaseClass)

                   || schemaResponseObjects.SelectMany(o => o.Value.Properties).Any(x => x.Type == obj.Type ||
                                                                                    x.Type == CollectionTypeHelper.GetCollectionType(obj.Type) ||
                                                                                    x.Type == obj.BaseClass ||
                                                                                    CollectionTypeHelper.GetCollectionType(x.Type) == obj.Type ||
                                                                                    x.Type == CollectionTypeHelper.GetCollectionType(obj.BaseClass) ||
                                                                                    CollectionTypeHelper.GetCollectionType(x.Type) == obj.BaseClass));
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
0
 public bool IsUsedAsParameterInAnyMethod(IEnumerable <ClassObject> classes, ApiObject requestObj)
 {
     return(classes.Any(c => c.Methods
                        .Any(m => m.Parameter != null &&
                             (m.Parameter.Type == requestObj.Type || m.Parameter.Type == CollectionTypeHelper.GetCollectionType(requestObj.Type) ||
                              CollectionTypeHelper.GetCollectionType(m.Parameter.Type) == requestObj.Type))));
 }
Ejemplo n.º 5
0
        public static bool HasSameProperties(ApiObject apiObject, IDictionary <string, ApiObject> objects, string key, IDictionary <string, ApiObject> otherObjects,
                                             IDictionary <string, ApiObject> schemaObjects)
        {
            var obj = FindObjectByKeyNameOrType(apiObject, key, objects, otherObjects, schemaObjects);

            if (obj == null)
            {
                throw new InvalidOperationException("Could not find object with key " + key);
            }

            if (!string.IsNullOrWhiteSpace(obj.GeneratedCode))
            {
                if (objects.Any(o => o.Value.GeneratedCode == obj.GeneratedCode) ||
                    otherObjects.Any(o => o.Value.GeneratedCode == obj.GeneratedCode) ||
                    schemaObjects.Any(o => o.Value.GeneratedCode == obj.GeneratedCode))
                {
                    return(true);
                }
            }

            if (obj.Properties.Count != apiObject.Properties.Count)
            {
                return(false);
            }

            return(apiObject.Properties.All(property => obj.Properties.Any(p => p.Name == property.Name && p.Type == property.Type)));
        }
Ejemplo n.º 6
0
        private string HandleMultipleSchemaType(IEnumerable <Response> responses, RAML.Parser.Model.EndPoint resource, Operation method, string fullUrl)
        {
            var properties = GetProperties(responses, resource, method, fullUrl);

            if (properties.Count == 0)
            {
                return("string");
            }

            if (properties.Count == 1)
            {
                return(properties.First().Type);
            }

            // Build a new response object containing all types
            var key       = GeneratorServiceHelper.GetKeyForResource(method, resource);
            var name      = NetNamingMapper.GetObjectName("Multiple" + key);
            var apiObject = new ApiObject
            {
                Name        = name,
                Description = "Multiple Response Types " + string.Join(", ", properties.Select(p => p.Name)),
                Properties  = properties,
                IsMultiple  = true
            };

            schemaResponseObjects.Add(new KeyValuePair <string, ApiObject>(name, apiObject));
            return(name);
        }
Ejemplo n.º 7
0
        public static ApiObject FirstOrDefaultWithSameProperties(ApiObject apiObject, IDictionary <string, ApiObject> objects, string key,
                                                                 IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects)
        {
            var objs = FindAllObjectsWithSameProperties(apiObject, key, objects, otherObjects, schemaObjects);

            return(objs.FirstOrDefault(o => apiObject.Properties.All(property => o.Properties.Any(p => p.Name == property.Name && p.Type == property.Type))));
        }
Ejemplo n.º 8
0
        public static string GetTypeFromApiObject(ApiObject apiObject)
        {
            if (apiObject.IsArray)
            {
                if (string.IsNullOrWhiteSpace(apiObject.Type))
                {
                    return(CollectionTypeHelper.GetCollectionType(apiObject.Name));
                }

                if (CollectionTypeHelper.IsCollection(apiObject.Type))
                {
                    return(apiObject.Type);
                }

                return(CollectionTypeHelper.GetCollectionType(apiObject.Type));
            }
            if (apiObject.IsMap)
            {
                return(apiObject.Type);
            }

            if (apiObject.IsScalar)
            {
                return(apiObject.Properties.First().Type);
            }

            if (!string.IsNullOrWhiteSpace(apiObject.Type) && apiObject.Type != apiObject.Name)
            {
                return(apiObject.Type);
            }

            return(apiObject.Name);
        }
Ejemplo n.º 9
0
        private static List <ApiObject> FindAllObjects(ApiObject apiObject, IDictionary <string, ApiObject> objects, string key)
        {
            var found = new List <ApiObject>();

            if (!string.IsNullOrWhiteSpace(key))
            {
                var byKey = new Func <KeyValuePair <string, ApiObject>, bool>(o => o.Key != null && o.Value != null && o.Key.StartsWith(key) &&
                                                                              o.Value.Properties.Count == apiObject.Properties.Count);
                if (objects.Any(byKey))
                {
                    found.Add(objects.First(byKey).Value);
                }
            }

            var byName = new Func <KeyValuePair <string, ApiObject>, bool>(o => o.Value.Name != null && o.Value.Name.StartsWith(apiObject.Name) &&
                                                                           o.Value.Properties.Count == apiObject.Properties.Count);

            if (objects.Any(byName))
            {
                found.Add(objects.First(byName).Value);
            }

            var byType = new Func <KeyValuePair <string, ApiObject>, bool>(o => o.Value.Type != null && o.Value.Type.StartsWith(apiObject.Type) &&
                                                                           o.Value.Properties.Count == apiObject.Properties.Count);

            if (objects.Any(byType))
            {
                found.Add(objects.First(byType).Value);
            }

            return(found);
        }
Ejemplo n.º 10
0
        //private static ApiObject FindObject(IHasName apiObject, IDictionary<string, ApiObject> objects, string key)
        //{
        //    var foundKey = objects.Keys.FirstOrDefault(k => string.Equals(k, key));
        //    if (foundKey != null)
        //        return objects[foundKey];

        //    var byName = new Func<KeyValuePair<string, ApiObject>, bool>(o => o.Value.Name == apiObject.Name);
        //    if (objects.Any(byName))
        //        return objects.First(byName).Value;

        //    return null;
        //}

        private static ApiObject FindObject(ApiObject apiObject, IDictionary <string, ApiObject> objects, string key)
        {
            var foundKey = objects.Keys.FirstOrDefault(k => string.Equals(k, key));

            if (foundKey != null)
            {
                return(objects[foundKey]);
            }

            var byName = new Func <KeyValuePair <string, ApiObject>, bool>(o => o.Value.Name == apiObject.Name);

            if (objects.Any(byName))
            {
                return(objects.First(byName).Value);
            }

            var byType = new Func <KeyValuePair <string, ApiObject>, bool>(o => o.Value.Type == apiObject.Type);

            if (objects.Any(byType))
            {
                return(objects.First(byType).Value);
            }

            return(null);
        }
Ejemplo n.º 11
0
        private string GetReturnTypeFromResponseByKey(string key)
        {
            ApiObject apiObject = null;

            if (schemaObjects.ContainsKey(key))
            {
                apiObject = schemaObjects[key];
            }

            if (schemaResponseObjects.ContainsKey(key))
            {
                apiObject = schemaResponseObjects[key];
            }

            var nameKey = NetNamingMapper.GetObjectName(key);

            if (schemaObjects.ContainsKey(nameKey))
            {
                apiObject = schemaObjects[nameKey];
            }

            if (schemaResponseObjects.ContainsKey(nameKey))
            {
                apiObject = schemaResponseObjects[nameKey];
            }

            return(RamlTypesHelper.GetTypeFromApiObject(apiObject));
        }
Ejemplo n.º 12
0
        public static IEnumerable <ApiObject> FindAllObjectsWithSameProperties(ApiObject apiObject, string key, IDictionary <string, ApiObject> objects,
                                                                               IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects)
        {
            var objs = FindAllObjects(apiObject, schemaObjects, key);

            objs.AddRange(FindAllObjects(apiObject, objects, key));
            objs.AddRange(FindAllObjects(apiObject, otherObjects, key));
            return(objs);
        }
Ejemplo n.º 13
0
 public bool IsUsedAsResponseInAnyMethod(IEnumerable <ClassObject> classes, ApiObject apiObj)
 {
     return(classes.Any(c => c.Methods.Any(m => m.ReturnType == apiObj.Type ||
                                           m.ReturnType == CollectionTypeHelper.GetCollectionType(apiObj.Type) ||
                                           CollectionTypeHelper.GetCollectionType(m.ReturnType) == apiObj.Type ||
                                           m.ReturnType == apiObj.Name ||
                                           (m.ReturnTypeObject != null && m.ReturnTypeObject.Properties != null &&
                                            m.ReturnTypeObject.Properties.Any(x => x.Type == apiObj.Type || x.Type == CollectionTypeHelper.GetCollectionType(apiObj.Type) ||
                                                                              CollectionTypeHelper.GetCollectionType(x.Type) == apiObj.Type)))));
 }
Ejemplo n.º 14
0
        //private string GetParamType(MimeType mimeType, ApiObject apiObject)
        //{
        //    if (mimeType.Type.Contains("<<") && mimeType.Type.Contains(">>"))
        //        return RamlTypesHelper.GetTypeFromApiObject(apiObject);

        //    return DecodeRequestRaml1Type(mimeType.Type);
        //}

        private GeneratorParameter CreateGeneratorParameter(ApiObject apiObject)
        {
            var generatorParameter = new GeneratorParameter
            {
                Name        = apiObject.Name.ToLower(),
                Type        = RamlTypesHelper.GetTypeFromApiObject(apiObject),
                Description = apiObject.Description
            };

            return(generatorParameter);
        }
Ejemplo n.º 15
0
        public ApiObject GetQueryObject(ClientGeneratorMethod generatedMethod, Operation method, string objectName)
        {
            var queryObject = new ApiObject {
                Name = generatedMethod.Name + objectName + "Query"
            };

            queryObject.Properties = ParseParameters(method);


            return(queryObject);
        }
Ejemplo n.º 16
0
        public static bool AnyWithSameProperties(ApiObject apiObject, IDictionary <string, ApiObject> objects, string key, IDictionary <string, ApiObject> otherObjects,
                                                 IDictionary <string, ApiObject> schemaObjects)
        {
            var objs = FindAllObjectsWithSameProperties(apiObject, key, objects, otherObjects, schemaObjects);

            if (objs.Any(obj => apiObject.Properties.All(property => obj.Properties.Any(p => p.Name == property.Name && p.Type == property.Type))))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        private void AddNewObject(Shape shape, ApiObject apiObj)
        {
            var amfId = shape.Id;

            if (string.IsNullOrWhiteSpace(amfId))
            {
                amfId = apiObj.Name;
            }

            if (!newObjects.ContainsKey(amfId))
            {
                newObjects.Add(amfId, apiObj);
            }
        }
Ejemplo n.º 18
0
        public void Generate(EndPoint resource, string url, ClientGeneratorMethod clientGeneratorMethod,
                             IDictionary <string, ApiObject> uriParameterObjects, IDictionary <string, Parameter> parentUriParameters)
        {
            var parameters = GetUriParameters(resource, url, parentUriParameters).ToArray();

            clientGeneratorMethod.UriParameters = parameters;

            if (!parameters.Any())
            {
                return;
            }

            var name = NetNamingMapper.GetObjectName(url) + "UriParameters";

            clientGeneratorMethod.UriParametersType = name;
            if (uriParameterObjects.ContainsKey(name))
            {
                return;
            }

            var properties = new List <Property>();

            if (resource.Parameters != null)
            {
                properties.AddRange(queryParametersParser.ConvertParametersToProperties(resource.Parameters));
            }

            var urlParameters     = ExtractParametersFromUrl(url).ToArray();
            var matchedParameters = MatchParameters(parentUriParameters, urlParameters);

            foreach (var urlParameter in matchedParameters)
            {
                var property = ConvertGeneratorParamToProperty(urlParameter);
                if (properties.All(p => !String.Equals(property.Name, p.Name, StringComparison.InvariantCultureIgnoreCase)))
                {
                    properties.Add(property);
                }
            }

            var apiObject = new ApiObject
            {
                Name        = name,
                Description = "Uri Parameters for resource " + resource.Path,
                Properties  = properties
            };

            uriParameterObjects.Add(name, apiObject);
        }
Ejemplo n.º 19
0
        public static ApiObject FindObjectWithSameProperties(ApiObject apiObject, string key, IDictionary <string, ApiObject> objects,
                                                             IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects)
        {
            var obj = FindObject(apiObject, schemaObjects, key);

            if (obj == null)
            {
                obj = FindObject(apiObject, objects, key);
            }

            if (obj == null)
            {
                obj = FindObject(apiObject, otherObjects, key);
            }

            return(obj);
        }
Ejemplo n.º 20
0
        public static ApiObject FindObjectByKeyNameOrType(ApiObject apiObject, string key, IDictionary <string, ApiObject> objects,
                                                          IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects)
        {
            var obj = FindObject(apiObject, schemaObjects, key);

            if (obj == null)
            {
                obj = FindObject(apiObject, objects, key);
            }

            if (obj == null)
            {
                obj = FindObject(apiObject, otherObjects, key);
            }

            return(obj);
        }
Ejemplo n.º 21
0
        private ApiObject HandleTypeDuplication(Guid id, ApiObject apiObj, string key, IDictionary <Guid, string> linkedType)
        {
            var match = UniquenessHelper.FirstOrDefaultWithSameProperties(apiObj, existingObjects, key, newObjects, emptyDic);

            if (match != null)
            {
                if (!linkedType.ContainsKey(id))
                {
                    linkedType.Add(id, match.Type);
                }
            }
            else
            {
                apiObj.Type = UniquenessHelper.GetUniqueName(existingObjects, apiObj.Type, newObjects, emptyDic);
            }
            return(match);
        }
Ejemplo n.º 22
0
        private ApiObject HandleNameDuplication(Guid id, ApiObject apiObj, string key, IDictionary <Guid, string> linkedType)
        {
            var match = UniquenessHelper.FirstOrDefaultWithSameProperties(apiObj, existingObjects, key, newObjects, emptyDic);

            if (match != null)
            {
                linkedType.Add(id, match.Type);
            }
            else
            {
                apiObj.Name = UniquenessHelper.GetUniqueName(existingObjects, apiObj.Name, newObjects, emptyDic);
                foreach (var prop in apiObj.Properties)
                {
                    prop.ParentClassName = apiObj.Name;
                }
            }
            return(match);
        }
Ejemplo n.º 23
0
 private bool NeedsFixing(ApiObject obj, Property prop)
 {
     return(prop.TypeId == obj.Id && ((!CollectionTypeHelper.IsCollection(prop.Type) && prop.Type != obj.Name) ||
                                      (CollectionTypeHelper.IsCollection(prop.Type) && CollectionTypeHelper.GetCollectionType(obj.Type) != prop.Type)));
 }
Ejemplo n.º 24
0
 private bool IsUsedAsQueryOrUriParameter(IEnumerable <Core.WebApiGenerator.ControllerObject> controllers, ApiObject obj)
 {
     return(controllers.Any(c => c.Methods.Any(m => (m.QueryParameters != null && m.QueryParameters.Any(qp => qp.Type == obj.Type)) ||
                                               (m.UriParameters != null && m.UriParameters.Any(up => up.Type == obj.Type)))));
 }
Ejemplo n.º 25
0
 public bool IsUsedAnywhere(IEnumerable <Core.ClientGenerator.ClassObject> classes, ApiObject obj)
 {
     return(IsUsedAsParameterInAnyMethod(classes, obj) || IsUsedAsResponseInAnyMethod(classes, obj) ||
            IsUsedAsReferenceInAnyObject(obj) || IsUsedAsUriParameter(classes, obj));
 }
Ejemplo n.º 26
0
        private Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> > ParseObject(Guid id, string key, Shape shape,
                                                                                                                                IDictionary <string, ApiObject> existingObjects, bool isRootType)
        {
            if (AlreadyExists(existingObjects, existingEnums, shape.Id))
            {
                return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >
                           (newObjects, newEnums, new Dictionary <Guid, string>()));
            }

            // if is array of scalar or array of object there's no new object, except when is a root type
            if (!isRootType && shape is ArrayShape array && (array.Items is ScalarShape || array.Items is AnyShape))
            {
                return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >
                           (newObjects, newEnums, new Dictionary <Guid, string>()));
            }

            var linkedType = new Dictionary <Guid, string>();

            var apiObj = new ApiObject
            {
                Id          = id,
                AmfId       = shape.Id,
                BaseClass   = GetBaseClass(shape),
                IsArray     = shape is ArrayShape,
                IsScalar    = shape is ScalarShape,
                IsUnionType = shape is UnionShape,
                Name        = NetNamingMapper.GetObjectName(key),
                Type        = NetNamingMapper.GetObjectName(key),
                Description = shape.Description,
                Example     = MapExample(shape)
            };

            if (isRootType && apiObj.IsScalar)
            {
                apiObj.Type = NewNetTypeMapper.GetNetType(shape, existingObjects);
            }

            if (isRootType && apiObj.IsArray && shape is ArrayShape arrShape)
            {
                var itemShape = arrShape.Items;
                if (itemShape is NodeShape)
                {
                    var itemId = Guid.NewGuid();
                    ParseObject(itemId, itemShape.Name, itemShape, existingObjects, false);

                    apiObj.Type = NewNetTypeMapper.GetNetType(shape, existingObjects);
                }
                else
                {
                    //if (newObjects.ContainsKey(itemShape.Id))
                    //    apiObj.Type = CollectionTypeHelper.GetCollectionType(newObjects[itemShape.Id].Type);
                    //else if(existingObjects.ContainsKey(itemShape.Id))
                    //    apiObj.Type = CollectionTypeHelper.GetCollectionType(existingObjects[itemShape.Id].Type);
                    //else
                    apiObj.Type = NewNetTypeMapper.GetNetType(shape, existingObjects);
                }
            }

            if (shape is NodeShape node && node.Properties.Count() == 1 && node.Properties.First().Path != null && node.Properties.First().Path.StartsWith("/") &&
                node.Properties.First().Path.EndsWith("/"))
            {
                apiObj.IsMap = true;
                var valueType = "object";
                if (node.Properties.First().Range != null)
                {
                    valueType = NewNetTypeMapper.GetNetType(node.Properties.First().Range, existingObjects);
                }

                apiObj.Type = $"Dictionary<string, {valueType}>";
                AddNewObject(shape, apiObj);
                return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >(newObjects, newEnums, linkedType));
            }

            apiObj.Properties = MapProperties(shape, apiObj.Name).ToList();

            ApiObject match = null;

            if (existingObjects.Values.Any(o => o.Name == apiObj.Name) || newObjects.Values.Any(o => o.Name == apiObj.Name))
            {
                if (UniquenessHelper.HasSameProperties(apiObj, existingObjects, key, newObjects, emptyDic))
                {
                    return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >(newObjects, newEnums, linkedType));
                }

                match = HandleNameDuplication(id, apiObj, key, linkedType);
            }

            if (existingObjects.Values.Any(o => o.Type == apiObj.Type) || newObjects.Values.Any(o => o.Type == apiObj.Type))
            {
                if (UniquenessHelper.HasSameProperties(apiObj, existingObjects, key, newObjects, emptyDic))
                {
                    return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >(newObjects, newEnums, linkedType));
                }

                match = HandleTypeDuplication(id, apiObj, key, linkedType);
            }

            if (match != null)
            {
                return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >(newObjects, newEnums, linkedType));
            }

            //if (match == null)
            //{
            //    match = UniquenessHelper.FirstOrDefaultWithSameProperties(apiObj, existingObjects, key, newObjects, emptyDic);
            //    if (match != null)
            //    {
            //        if (!linkedType.ContainsKey(id))
            //            linkedType.Add(id, match.Type);
            //    }
            //}

            if (shape.Inherits != null && shape.Inherits.Count() == 1)
            {
                var baseClass = NewNetTypeMapper.GetNetType(shape.Inherits.First(), existingObjects, newObjects, existingEnums, newEnums);
                if (!string.IsNullOrWhiteSpace(baseClass))
                {
                    apiObj.BaseClass = CollectionTypeHelper.GetConcreteType(baseClass);
                }
            }

            AddNewObject(shape, apiObj);

            return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum>, IDictionary <Guid, string> >(newObjects, newEnums, linkedType));
        }
Ejemplo n.º 27
0
 private bool IsUsedAsUriParameter(IEnumerable <Core.ClientGenerator.ClassObject> classes, ApiObject obj)
 {
     return(classes.Any(c => c.Methods.Any(m => (m.UriParameters != null && m.UriParameters.Any(up => up.Type == obj.Type)))));
 }
Ejemplo n.º 28
0
 public bool IsUsedAsResponseInAnyMethod(IEnumerable <Core.WebApiGenerator.ControllerObject> controllers, ApiObject requestObj)
 {
     return(controllers.Any(c => c.Methods.Any(m => m.ReturnType == requestObj.Type ||
                                               m.ReturnType == CollectionTypeHelper.GetCollectionType(requestObj.Type) ||
                                               CollectionTypeHelper.GetCollectionType(m.ReturnType) == requestObj.Type ||
                                               m.ReturnType == requestObj.Name ||
                                               m.ReturnType == CollectionTypeHelper.GetCollectionType(requestObj.Name) ||
                                               CollectionTypeHelper.GetCollectionType(m.ReturnType) == requestObj.Name)));
 }
Ejemplo n.º 29
0
        private Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum> > ParseObject(string key, Shape shape,
                                                                                                    IDictionary <string, ApiObject> existingObjects, bool isRootType)
        {
            var apiObj = new ApiObject
            {
                BaseClass   = GetBaseClass(shape),
                IsArray     = shape is ArrayShape,
                IsScalar    = shape is ScalarShape,
                IsUnionType = shape is UnionShape,
                Name        = NetNamingMapper.GetObjectName(key),
                Type        = NetNamingMapper.GetObjectName(key),
                Description = shape.Description,
                Example     = MapExample(shape)
            };

            if (isRootType && (apiObj.IsArray || apiObj.IsScalar))
            {
                apiObj.Type = NewNetTypeMapper.GetNetType(shape, existingObjects);
            }

            if (shape is NodeShape node && node.Properties.Count() == 1 && node.Properties.First().Path.StartsWith("/") &&
                node.Properties.First().Path.EndsWith("/"))
            {
                apiObj.IsMap = true;
                var valueType = "object";
                if (node.Properties.First().Range != null)
                {
                    valueType = NewNetTypeMapper.GetNetType(node.Properties.First().Range, existingObjects);
                }

                apiObj.Type = $"Dictionary<string, {valueType}>";
                new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum> >(newObjects, newEnums);
            }

            apiObj.Properties = MapProperties(shape, apiObj.Name).ToList();

            if (existingObjects.Values.Any(o => o.Name == apiObj.Name))
            {
                if (UniquenessHelper.HasSameProperties(apiObj, existingObjects, key, new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>()))
                {
                    return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum> >(newObjects, newEnums));
                }

                apiObj.Name = UniquenessHelper.GetUniqueName(existingObjects, apiObj.Name, new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>());
                foreach (var prop in apiObj.Properties)
                {
                    prop.ParentClassName = apiObj.Name;
                }
            }
            if (existingObjects.Values.Any(o => o.Type == apiObj.Type))
            {
                if (UniquenessHelper.HasSameProperties(apiObj, existingObjects, key, new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>()))
                {
                    return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum> >(newObjects, newEnums));
                }

                apiObj.Type = UniquenessHelper.GetUniqueName(existingObjects, apiObj.Type, new Dictionary <string, ApiObject>(), new Dictionary <string, ApiObject>());
            }

            if (!newObjects.ContainsKey(apiObj.Type))
            {
                newObjects.Add(apiObj.Type, apiObj);
            }

            return(new Tuple <IDictionary <string, ApiObject>, IDictionary <string, ApiEnum> >(newObjects, newEnums));
        }
Ejemplo n.º 30
0
 // To use with XML Schema objects
 public static bool HasSameProperties(ApiObject apiObject, IDictionary <string, ApiObject> objects, IDictionary <string, ApiObject> otherObjects, IDictionary <string, ApiObject> schemaObjects)
 {
     return(objects.Any(o => o.Value.GeneratedCode == apiObject.GeneratedCode) ||
            otherObjects.Any(o => o.Value.GeneratedCode == apiObject.GeneratedCode) ||
            schemaObjects.Any(o => o.Value.GeneratedCode == apiObject.GeneratedCode));
 }