コード例 #1
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 type = GetRamlType(kv);
                        var key  = kv.Key;

                        if (preffix != null)
                        {
                            type.LibraryName = preffix;
                            key = preffix + "." + key;
                        }

                        ramlTypes.Add(key, type);
                    }
                }
                ParseDefferredTypes();
                return;
            }

            var types = dynamicRaml["types"] as IDictionary <string, object>;

            if (types == null)
            {
                return;
            }

            foreach (var type in types)
            {
                var ramlType = GetRamlType(type);
                ramlType.LibraryName = preffix;

                var key = type.Key;
                if (ramlType.LibraryName != null)
                {
                    key = ramlType.LibraryName + "." + key;
                }
                ramlTypes.Add(key, ramlType);
            }

            ParseDefferredTypes();
        }
コード例 #2
0
        public void ShouldParseRquiredAttribute()
        {
            var ramlTypesOrderedDictionary = new RamlTypesOrderedDictionary();
            var ramlType = new RamlType
            {
                Type   = "object",
                Object = new ObjectType
                {
                    Properties = new Dictionary <string, RamlType>()
                }
            };
            var property = new Parser.Expressions.Property
            {
                Type        = "string",
                Required    = true,
                DisplayName = "subject"
            };
            var subject = new RamlType
            {
                Type   = "string",
                Scalar = property
            };

            ramlType.Object.Properties.Add("subject", subject);
            ramlTypesOrderedDictionary.Add("mail", ramlType);
            var objects    = new Dictionary <string, ApiObject>();
            var typeParser = new RamlTypeParser(ramlTypesOrderedDictionary,
                                                objects, "SomeNamespace", new Dictionary <string, ApiEnum>(),
                                                new Dictionary <string, string>());

            typeParser.Parse();
            Assert.AreEqual(true, objects.First().Value.Properties.First().Required);
        }
コード例 #3
0
        public void ShouldSerializeObjectRamlType()
        {
            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
                          } }
                    }
                }
            });
            var doc = new RamlDocument
            {
                Types = ramlTypesOrderedDictionary
            };
            var res = serializer.Serialize(doc);

            Assert.True(res.Contains("types:" + Environment.NewLine));
            Assert.True(res.Contains("  - Person:" + Environment.NewLine));
            Assert.True(res.Contains("      properties:" + Environment.NewLine));
            Assert.True(res.Contains("          lastname:" + Environment.NewLine));
            Assert.True(res.Contains("          firstname?:" + Environment.NewLine));
        }
コード例 #4
0
        public void ShouldParseOptionalStringArrayProperty()
        {
            var ramlTypesOrderedDictionary = new RamlTypesOrderedDictionary();
            var ramlType = new RamlType
            {
                Type   = "object",
                Object = new ObjectType
                {
                    Properties = new Dictionary <string, RamlType>()
                }
            };
            var messages = new RamlType
            {
                Type  = "string[]",
                Array = new ArrayType()
            };

            ramlType.Object.Properties.Add("Messages?", messages);
            ramlTypesOrderedDictionary.Add("Test", ramlType);

            var objects    = new Dictionary <string, ApiObject>();
            var typeParser = new RamlTypeParser(ramlTypesOrderedDictionary,
                                                objects, "SomeNamespace", new Dictionary <string, ApiEnum>(),
                                                new Dictionary <string, string>());

            typeParser.Parse();
            Assert.AreEqual("Messages", objects.First().Value.Properties.First().Name);
            Assert.AreEqual(false, objects.First().Value.Properties.First().Required);
        }
コード例 #5
0
        public static void AddTypes(RamlTypesOrderedDictionary ramlTypes_, IDictionary <string, object> dynamicRaml, string preffix_ = null)
        {
            preffix   = preffix_;
            ramlTypes = ramlTypes_;
            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));
                    }
                }
                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));
            }
        }
コード例 #6
0
        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);
        }