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));
        }
        public void Serialize(StringBuilder sb, RamlTypesOrderedDictionary types)
        {
            if (types == null || types.Count == 0)
                return;

            sb.AppendLine("types:");
            foreach (var key in types.Keys)
            {
                var ramlType = types[key];
                ramlType.Required = true;
                Serialize(sb, "- " + key, ramlType, 2);
            }
        }
예제 #3
0
 public RamlDocument()
 {
     RamlVersion       = RamlVersion.Version08;
     Resources         = new Collection <Resource>();
     Documentation     = new Collection <DocumentationItem>();
     BaseUriParameters = new Dictionary <string, Parameter>();
     SecuredBy         = new Collection <string>();
     Protocols         = new Collection <Protocol>();
     SecuritySchemes   = new Collection <IDictionary <string, SecurityScheme> >();
     ResourceTypes     = new Collection <IDictionary <string, ResourceType> >();
     Traits            = new Collection <IDictionary <string, Method> >();
     Schemas           = new Collection <IDictionary <string, string> >();
     Annotations       = new Dictionary <string, object>();
     Types             = new RamlTypesOrderedDictionary();
 }
예제 #4
0
 public RamlDocument()
 {
     RamlVersion = RamlVersion.Version08;
     Resources = new Collection<Resource>();
     Documentation = new Collection<DocumentationItem>();
     BaseUriParameters = new Dictionary<string, Parameter>();
     SecuredBy = new Collection<string>();
     Protocols = new Collection<Protocol>();
     SecuritySchemes = new Collection<IDictionary<string, SecurityScheme>>();
     ResourceTypes = new Collection<IDictionary<string, ResourceType>>();
     Traits = new Collection<IDictionary<string, Method>>();
     Schemas = new Collection<IDictionary<string, string>>();
     Annotations = new Dictionary<string, object>();
     Types = new RamlTypesOrderedDictionary();
 }
예제 #5
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();
        }
 public Raml1TypeBuilder(RamlTypesOrderedDictionary raml1Types)
 {
     this.raml1Types = raml1Types;
 }
 public void TestSetup()
 {
     raml1Types = new RamlTypesOrderedDictionary();
     raml1TypeBuilder = new Raml1TypeBuilder(raml1Types);
 }