예제 #1
0
        private static ObjectType GetObject(IDictionary <string, object> dynamicRaml)
        {
            var obj = new ObjectType();

            obj.AdditionalProperties = DynamicRamlParser.GetValueOrNull(dynamicRaml, "additionalProperties");
            obj.Discriminator        = DynamicRamlParser.GetValueOrNull(dynamicRaml, "discriminator");
            obj.DiscriminatorValue   = DynamicRamlParser.GetStringOrNull(dynamicRaml, "discriminatorValue");
            obj.MaxProperties        = DynamicRamlParser.GetIntOrNull(dynamicRaml, "maxProperties");
            obj.MinProperties        = DynamicRamlParser.GetIntOrNull(dynamicRaml, "minProperties");
            obj.PatternProperties    = DynamicRamlParser.GetValueOrNull(dynamicRaml, "patternProperties");

            ParseProperties(dynamicRaml, obj);
            return(obj);
        }
예제 #2
0
        private static ObjectType GetObject(IDictionary <string, object> dynamicRaml)
        {
            var obj = new ObjectType();

            obj.AdditionalProperties = DynamicRamlParser.GetValueOrNull(dynamicRaml, "additionalProperties");
            obj.Discriminator        = DynamicRamlParser.GetValueOrNull(dynamicRaml, "discriminator");
            obj.DiscriminatorValue   = DynamicRamlParser.GetStringOrNull(dynamicRaml, "discriminatorValue");
            obj.MaxProperties        = DynamicRamlParser.GetIntOrNull(dynamicRaml, "maxProperties");
            obj.MinProperties        = DynamicRamlParser.GetIntOrNull(dynamicRaml, "minProperties");
            obj.PatternProperties    = DynamicRamlParser.GetValueOrNull(dynamicRaml, "patternProperties");

            var properties = new Dictionary <string, RamlType>();

            if (dynamicRaml.ContainsKey("properties"))
            {
                foreach (var property in (IDictionary <string, object>)dynamicRaml["properties"])
                {
                    properties.Add(property.Key, GetRamlType(property));
                }
            }

            obj.Properties = properties;
            return(obj);
        }
예제 #3
0
        public static RamlType GetRamlType(KeyValuePair <string, object> type)
        {
            var key      = type.Key;
            var required = true;

            if (key.EndsWith("?"))
            {
                key      = key.Substring(0, key.Length - 1);
                required = false;
            }

            var ramlType = new RamlType();

            ramlType.Name     = key;
            ramlType.Required = required;

            var simpleProperty = type.Value as string;

            if (simpleProperty != null)
            {
                if (simpleProperty.StartsWith("<"))
                {
                    ramlType.External = new ExternalType
                    {
                        Xml = simpleProperty
                    };
                    return(ramlType);
                }
                if (simpleProperty.StartsWith("{"))
                {
                    ramlType.External = new ExternalType
                    {
                        Schema = simpleProperty
                    };
                    return(ramlType);
                }

                ramlType.Scalar = GetScalar(type, required);
                return(ramlType);
            }

            var dynamicRaml = type.Value as IDictionary <string, object>;

            if (dynamicRaml == null)
            {
                throw new InvalidOperationException("Cannot parse type: " + type.Key);
            }

            ramlType = new RamlType
            {
                Name            = type.Key,
                Type            = GetType((IDictionary <string, object>)type.Value),
                Example         = DynamicRamlParser.GetStringOrNull((IDictionary <string, object>)type.Value, "example"),
                Facets          = DynamicRamlParser.GetDictionaryOrNull <object>((IDictionary <string, object>)type.Value, "facets"),
                OtherProperties = GetOtherProperties((IDictionary <string, object>)type.Value)
            };

            SetPropertiesByType(type, ramlType);

            return(ramlType);
        }