Ejemplo n.º 1
0
 protected abstract TType RamlTypeToSchemaType(RamlType ramlType, ConversionOptions options);
Ejemplo n.º 2
0
 protected abstract void ProcessRootType(RamlType ramlType, ConversionOptions options);
Ejemplo n.º 3
0
        private List <RamlType> GetRamlTypes(Dictionary <object, object> types)
        {
            if (types == null)
            {
                return(null);
            }

            var ramlTypes = new List <RamlType>();

            foreach (object key in types.Keys)
            {
                var ramlType = new RamlType();
                var type     = types[key] as Dictionary <object, object>;
                ramlType.Name = key as string;

                // do not generate special collection type
                if (ramlType.Name.Equals(StringConstants.Collection, StringComparison.InvariantCulture))
                {
                    break;
                }

                ramlType.Description = GetValueByKey(type, RamlKeywords.Description) as string;

                ramlType.AdditionalProperties = true;

                ramlType.IsRootType = IsRootType(ramlType.Name);

                if (GetValueByKey(type, RamlKeywords.AdditionalProperties) as string == "false")
                {
                    ramlType.AdditionalProperties = false;
                }

                var baseTypeName = GetValueByKey(type, RamlKeywords.Type) as string;
                if (!string.IsNullOrEmpty(baseTypeName))
                {
                    // check for array
                    RamlArray ramlArray = null;

                    if (baseTypeName.Substring(baseTypeName.Length - 2).Equals(RamlKeywords.ArrayBrackets, StringComparison.InvariantCulture))
                    {
                        ramlArray = new RamlArray();
                        ramlArray.ItemsTypeName = baseTypeName.Substring(0, baseTypeName.Length - 2);
                    }
                    else if (baseTypeName.Equals(RamlKeywords.Array, StringComparison.Ordinal))
                    {
                        ramlArray = new RamlArray();
                        ramlArray.ItemsTypeName = GetValueByKey(type, RamlKeywords.Items) as string;
                    }
                    else if (baseTypeName.Length > StringConstants.Collection.Length)
                    {
                        if (baseTypeName.Substring(baseTypeName.Length - StringConstants.Collection.Length).Equals(StringConstants.Collection, StringComparison.InvariantCulture))
                        {
                            ramlArray = new RamlArray();
                            ramlArray.ItemsTypeName = GetValueByKey(type, RamlKeywords.Items) as string;
                            ramlArray.ItemName      = GetValueByKey(type, StringConstants.ItemName) as string;
                        }
                    }

                    if (ramlArray != null)
                    {
                        if (string.IsNullOrEmpty(ramlArray.ItemName))
                        {
                            ramlArray.ItemName = GetCollectionItemName(ramlType.Name);
                        }

                        ramlType.Array = ramlArray;
                        ramlTypes.Add(ramlType);
                        continue;
                    }

                    // it is not an array
                    if (!baseTypeName.Equals(RamlDataTypes.Object, StringComparison.InvariantCulture))
                    {
                        ramlType.Base         = new RamlBase();
                        ramlType.Base.Name    = baseTypeName;
                        ramlType.Base.Pattern = GetValueByKey(type, RamlKeywords.Pattern) as string;
                    }
                }


                // check for enum
                RamlEnum ramlEnum = null;

                var enumValues = GetValueByKey(type, RamlKeywords.Enum) as List <object>;

                if (enumValues != null)
                {
                    ramlEnum = new RamlEnum();

                    if (!string.IsNullOrEmpty(baseTypeName))
                    {
                        ramlEnum.ItemsTypeName = baseTypeName;
                    }
                    else
                    {
                        ramlEnum.ItemsTypeName = RamlDataTypes.String;
                    }

                    // get enum values
                    ramlEnum.EnumValues = new List <string>();

                    foreach (object enumValue in enumValues)
                    {
                        ramlEnum.EnumValues.Add(enumValue as string);
                    }

                    ramlType.Enum = ramlEnum;
                    ramlTypes.Add(ramlType);
                    continue;
                }

                var properties = GetValueByKey(type, RamlKeywords.Properties) as Dictionary <object, object>;
                if (properties != null)
                {
                    ramlType.Properties = GetRamlProperties(GetValueByKey(type, RamlKeywords.Properties) as Dictionary <object, object>);
                }

                ramlType.MinProperties = ConvertStringToInt(GetValueByKey(type, RamlKeywords.MinProperties) as string);
                ramlType.MaxProperties = ConvertStringToInt(GetValueByKey(type, RamlKeywords.MaxProperties) as string);

                ramlTypes.Add(ramlType);
            }

            return(ramlTypes);
        }