public void ShouldSerializeArrayRamlType()
        {
            var ramlTypesOrderedDictionary = new RamlTypesOrderedDictionary();
            ramlTypesOrderedDictionary.Add("Person", new RamlType
            {
                Object = new ObjectType
                {
                    Properties = new Dictionary<string, RamlType>()
                    {
                        {"firstname", new RamlType { Type = "string"}},
                        {"lastname", new RamlType { Type = "string", Required = true }}
                    }
                }
            });

            ramlTypesOrderedDictionary.Add("Persons", new RamlType
            {
                Array = new ArrayType
                {
                    Items = new RamlType
                    {
                        Type = "Person"
                    }
                }
            });
            var doc = new RamlDocument
            {
                Types = ramlTypesOrderedDictionary
            };
            var res = serializer.Serialize(doc);
            Assert.IsTrue(res.Contains("  - Persons:" + Environment.NewLine));
            Assert.IsTrue(res.Contains("      type: Person[]" + Environment.NewLine));
        }
예제 #2
0
        public static void AddTypes(RamlTypesOrderedDictionary ramlTypes_, IDictionary<string, object> dynamicRaml, string preffix_ = null)
        {
            preffix = preffix_;
            ramlTypes = ramlTypes_;
            defferredTypes.Clear();
            if (!dynamicRaml.ContainsKey("types"))
                return;

            var dynamicTypes = dynamicRaml["types"] as object[];
            if (dynamicTypes != null)
            {
                foreach (var dynamicType in dynamicTypes)
                {
                    var dic = dynamicType as IDictionary<string, object>;
                    foreach (var kv in dic)
                    {
                        var key = kv.Key;
                        if (preffix != null)
                            key = preffix + "." + key;
                        ramlTypes.Add(key, GetRamlType(kv));
                    }
                }
                ParseDefferredTypes();
                return;
            }

            var types = dynamicRaml["types"] as IDictionary<string, object>;
            if (types == null)
                return;

            foreach (var type in types)
            {
                var key = type.Key;
                if (preffix != null)
                    key = preffix + "." + key;
                ramlTypes.Add(key, GetRamlType(type));

            }

            ParseDefferredTypes();
        }