private void AddType(Type type, RamlType raml1Type)
        {
            var typeName = GetTypeName(type);

            // handle case of different types with same class name
            if (raml1Types.ContainsKey(typeName))
            {
                typeName = GetUniqueName(typeName);
            }

            raml1Types.Add(typeName, raml1Type);
        }
Esempio n. 2
0
        private string GetScalarType(RamlType ramlType)
        {
            var type = NetTypeMapper.GetNetType(ramlType.Scalar.Type, ramlType.Scalar.Format);

            if (type != null)
            {
                return(type);
            }

            if (!ramlTypes.ContainsKey(ramlType.Scalar.Type))
            {
                return("object");
            }

            var subRamlType = ramlTypes[ramlType.Scalar.Type];

            if (subRamlType.Scalar == null)
            {
                return(NetNamingMapper.GetObjectName(ramlType.Scalar.Type));
            }

            type = GetScalarType(subRamlType);
            if (type != null)
            {
                return(type);
            }

            throw new InvalidOperationException("Cannot determine type of scalar " + ramlType.Name);
        }
Esempio n. 3
0
        public void ShouldParseTypeWithNestedTypes()
        {
            var raml1Type = raml1TypeBuilder.Add(typeof(ForksPostResponse));

            Assert.That(!string.IsNullOrWhiteSpace(raml1Type));
            Assert.IsTrue(raml1Types.ContainsKey("ForksPostResponse"));
            Assert.IsTrue(raml1Types.ContainsKey("Owner"));
        }
        public void ShouldParseTypeWithNestedTypes()
        {
            var raml1Type = raml1TypeBuilder.Add(typeof(ForksPostResponse));

            Assert.NotNull(raml1Type);
            Assert.True(raml1Types.ContainsKey("ForksPostResponse"));
            Assert.True(raml1Types.ContainsKey("Owner"));
        }
Esempio n. 5
0
        private static void SetPropertiesByType(KeyValuePair <string, object> pair, RamlType ramlType)
        {
            var dynamicRaml = pair.Value as IDictionary <string, object>;

            if (PrimitiveTypes.Contains(ramlType.Type))
            {
                ramlType.Scalar = GetScalar(pair, ramlType.Required);
                return;
            }

            if (ramlType.Type.StartsWith("{"))
            {
                ramlType.External = new ExternalType {
                    Schema = ramlType.Type
                };
                return;
            }
            if (ramlType.Type.StartsWith("<"))
            {
                ramlType.External = new ExternalType {
                    Xml = ramlType.Type
                };
                return;
            }

            if (ramlType.Type == "object")
            {
                ramlType.Object = GetObject(dynamicRaml);
                return;
            }

            if (ramlType.Type == "array" || ramlType.Type.EndsWith("[]"))
            {
                ramlType.Array = GetArray(dynamicRaml, pair.Key);
                return;
            }

            if (ramlTypes.ContainsKey(ramlType.Type))
            {
                // Inheritance or Specialization
                var parentType = ramlTypes[ramlType.Type];

                if (parentType.Scalar != null)
                {
                    ramlType.Scalar = GetScalar(new KeyValuePair <string, object>(ramlType.Name, dynamicRaml), ramlType.Required);
                    return;
                }

                if (parentType.Object != null)
                {
                    ramlType.Object = GetObject(dynamicRaml);
                    return;
                }
            }

            if (ramlType.Type.Contains("|")) // Union Type
            {
                return;
            }

            throw new InvalidOperationException("Cannot parse type: " + ramlType.Type);
        }