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); }
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)); }
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); }
public RamlTypeParser(RamlTypesOrderedDictionary ramlTypes, IDictionary <string, ApiObject> schemaObjects, string targetNamespace, IDictionary <string, ApiEnum> enums, IDictionary <string, string> warnings) { this.ramlTypes = ramlTypes; this.schemaObjects = schemaObjects; this.targetNamespace = targetNamespace; this.enums = enums; this.warnings = warnings; }
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(); }
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); } }
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)); } }
public Raml1TypeBuilder(RamlTypesOrderedDictionary raml1Types) { this.raml1Types = raml1Types; }
public void TestSetup() { raml1Types = new RamlTypesOrderedDictionary(); raml1TypeBuilder = new Raml1TypeBuilder(raml1Types); }
public Raml1TypeBuilderTests() { raml1Types = new RamlTypesOrderedDictionary(); raml1TypeBuilder = new Raml1TypeBuilder(raml1Types); }