예제 #1
0
        private ApiObject ParseMap(RamlType ramlType, string key)
        {
            var name = NetNamingMapper.GetObjectName(key ?? ramlType.Name);
            var type = ramlType.Object.Properties.First().Value.Type;

            if (ramlType.Object.Properties.First().Value.Object != null && ramlType.Object.Properties.First().Value.Type == "object")
            {
                var itemName     = name + "Item";
                var nestedObject = ParseObject(itemName, ramlType.Object.Properties.First().Value);
                type = nestedObject.Name;
                schemaObjects.Add(itemName, nestedObject);
            }

            type = RamlTypesHelper.DecodeRaml1Type(type);

            if (NetTypeMapper.IsPrimitiveType(type))
            {
                type = NetTypeMapper.Map(type);
            }

            return(new ApiObject
            {
                Type = name,
                Name = name,
                BaseClass = "Dictionary<string," + type + ">",
                Description = ramlType.Description,
                Example = GetExample(ramlType.Example, ramlType.Examples),
                Properties = new Property[0],
                IsMap = true
            });
        }
예제 #2
0
        private string GetType(Parameter param)
        {
            if (param.Type == null)
            {
                return("string");
            }

            if (NetTypeMapper.IsPrimitiveType(param.Type))
            {
                return(NetTypeMapper.GetNetType(param.Type, param.Format) +
                       (NetTypeMapper.GetNetType(param.Type, param.Format) == "string" || param.Required ? "" : "?"));
            }

            var pureType = RamlTypesHelper.ExtractType(param.Type);

            if (schemaObjects.ContainsKey(pureType))
            {
                var apiObject = schemaObjects[pureType];
                return(RamlTypesHelper.GetTypeFromApiObject(apiObject));
            }

            return(RamlTypesHelper.DecodeRaml1Type(param.Type));
        }
        private ApiObject ParseUnion(string key, RamlType ramlType)
        {
            var name      = NetNamingMapper.GetObjectName(key);
            var apiObject = new ApiObject
            {
                IsUnionType = true,
                Name        = name,
                Description = ramlType.Description,
                Example     = GetExample(ramlType.Example, ramlType.Examples),
                Type        = NetNamingMapper.GetObjectName(key)
            };

            var originalType = ramlType.Type;

            var isArray = false;

            if (originalType.StartsWith("(") && originalType.EndsWith(")[]"))
            {
                isArray      = true;
                originalType = originalType.Substring(0, originalType.Length - 2);
            }
            originalType = originalType.Replace("(", string.Empty).Replace(")", string.Empty);

            var types = originalType.Split(new [] { "|" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var type in types)
            {
                apiObject.Properties.Add(new Property(name)
                {
                    Name = NetNamingMapper.GetPropertyName(type.Trim()),
                    Type = isArray
                        ? CollectionTypeHelper.GetCollectionType(RamlTypesHelper.DecodeRaml1Type(type.Trim()))
                        : RamlTypesHelper.DecodeRaml1Type(type.Trim())
                });
            }
            return(apiObject);
        }