private string ParseEnum(string key, Newtonsoft.JsonV4.Schema.JsonSchema schema, IDictionary <string, ApiEnum> enums, string description)
        {
            var name = NetNamingMapper.GetObjectName(key);

            var apiEnum = new ApiEnum
            {
                Name        = name,
                Description = description,
                Values      = schema.Enum.Select(e => RamlTypeParser.ToEnumValueName(e.ToString())).ToList()
            };

            if (enums.ContainsKey(name))
            {
                if (IsAlreadyAdded(enums, apiEnum))
                {
                    return(name);
                }

                apiEnum.Name = UniquenessHelper.GetUniqueName(enums, name);
            }

            enums.Add(apiEnum.Name, apiEnum);

            return(apiEnum.Name);
        }
Exemple #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);
        }
        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);
        }