Exemplo n.º 1
0
        private static Response Map(IDictionary <string, object> response)
        {
            if (response == null)
            {
                return(null);
            }

            return(new Response(response["name"] as string, response["description"] as string, response["statusCode"] as string,
                                ParameterMapper.Map(response["headers"] as object[]), PayloadMapper.Map(response["payloads"] as object[]),
                                ExampleMapper.Map(response["examples"] as object[])));
        }
Exemplo n.º 2
0
        private static SchemaShape MapSchema(IDictionary <string, object> schema)
        {
            if (schema == null)
            {
                return(null);
            }

            var @default = Map(schema["default"] as IDictionary <string, object>);

            return(new SchemaShape(schema["mediaType"] as string, schema["raw"] as string,
                                   DocumentationMapper.Map(schema["documentation"] as IDictionary <string, object>),
                                   XmlSerializerMapper.Map(schema["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(schema["examples"] as object[]),
                                   schema["id"] as string, schema["name"] as string, schema["displayName"] as string, schema["description"] as string, @default,
                                   StringEnumerationMapper.Map(schema["values"] as object[]), Map(schema["inherits"] as object[]),
                                   GetLinkTargetName(schema)));
        }
Exemplo n.º 3
0
        internal static Shape Map(IDictionary <string, object> shape)
        {
            if (shape == null)
            {
                return(null);
            }

            string linkTargetName = GetLinkTargetName(shape);

            if ((shape["isFile"] as bool?) == true)
            {
                var multipleOf       = ParameterMapperUtils.MapInt(shape, "multipleOf");
                var format           = shape["format"] as string;
                var exclusiveMaximum = shape["exclusiveMaximum"] is bool?ParameterMapperUtils.MapBool(shape, "exclusiveMaximum").ToString() : null;

                var exclusiveMinimum = shape["exclusiveMinimum"] is bool?ParameterMapperUtils.MapBool(shape, "exclusiveMinimum").ToString() : null;

                var maximum = shape["maximum"] is int?ParameterMapperUtils.MapInt(shape, "maximum").ToString() : null;

                var minimum = shape["minimum"] is int?ParameterMapperUtils.MapInt(shape, "minimum").ToString() : null;

                var maxLength = ParameterMapperUtils.MapInt(shape, "maxLength");
                var minLength = ParameterMapperUtils.MapInt(shape, "minLength");
                var pattern   = shape["pattern"] as string;
                return(GetFileShape(shape, linkTargetName, multipleOf, format, exclusiveMaximum, exclusiveMinimum, maximum, minimum, maxLength, minLength, pattern));
            }

            var @default = Map(shape["default"] as IDictionary <string, object>);

            if (shape["items"] != null) // Array
            {
                return(new ArrayShape(Map(shape["items"] as IDictionary <string, object>), ParameterMapperUtils.MapInt(shape, "minItems"),
                                      ParameterMapperUtils.MapInt(shape, "maxItems"), ParameterMapperUtils.MapBool(shape, "uniqueItems"),
                                      DocumentationMapper.Map(shape["documentation"] as IDictionary <string, object>),
                                      XmlSerializerMapper.Map(shape["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(shape["examples"] as object[]),
                                      shape["id"] as string, shape["name"] as string, shape["displayName"] as string, shape["description"] as string, @default,
                                      StringEnumerationMapper.Map(shape["values"] as object[]), Map(shape["inherits"] as object[]), linkTargetName));
            }

            if ((shape["properties"] as object[]) != null && (shape["properties"] as object[]).Length > 0) // Node
            {
                return(new NodeShape(ParameterMapperUtils.MapInt(shape, "minProperties"),
                                     ParameterMapperUtils.MapInt(shape, "maxProperties"), ParameterMapperUtils.MapBool(shape, "closed"),
                                     shape["discriminator"] as string, shape["discriminatorValue"] as string, ParameterMapperUtils.MapBool(shape, "readOnly"),
                                     PropertyShapeMapper.Map(shape["properties"] as object[]), PropertyDependenciesMapper.Map(shape["dependencies"] as object[]),
                                     DocumentationMapper.Map(shape["documentation"] as IDictionary <string, object>),
                                     XmlSerializerMapper.Map(shape["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(shape["examples"] as object[]),
                                     shape["id"] as string, shape["name"] as string, shape["displayName"] as string, shape["description"] as string, @default,
                                     StringEnumerationMapper.Map(shape["values"] as object[]), Map(shape["inherits"] as object[]), linkTargetName));
            }

            if (shape["dataType"] != null || (shape["fileTypes"] != null && (shape["fileTypes"] as object[]).Count() > 0)) // Scalar or File
            {
                var multipleOf       = ParameterMapperUtils.MapInt(shape, "multipleOf");
                var format           = shape["format"] as string;
                var exclusiveMaximum = shape["exclusiveMaximum"] is bool?ParameterMapperUtils.MapBool(shape, "exclusiveMaximum").ToString() : null;

                var exclusiveMinimum = shape["exclusiveMinimum"] is bool?ParameterMapperUtils.MapBool(shape, "exclusiveMinimum").ToString() : null;

                var maximum = shape["maximum"] is int?ParameterMapperUtils.MapInt(shape, "maximum").ToString() : null;

                var minimum = shape["minimum"] is int?ParameterMapperUtils.MapInt(shape, "minimum").ToString() : null;

                var maxLength = ParameterMapperUtils.MapInt(shape, "maxLength");
                var minLength = ParameterMapperUtils.MapInt(shape, "minLength");
                var pattern   = shape["pattern"] as string;

                if (shape["dataType"] != null) // Scalar
                {
                    var dataType = shape["dataType"] as string;

                    return(new ScalarShape(dataType, pattern, minLength, maxLength, minimum, maximum, exclusiveMinimum, exclusiveMaximum, format, multipleOf,
                                           DocumentationMapper.Map(shape["documentation"] as IDictionary <string, object>),
                                           XmlSerializerMapper.Map(shape["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(shape["examples"] as object[]),
                                           shape["id"] as string, shape["name"] as string, shape["displayName"] as string, shape["description"] as string, @default,
                                           StringEnumerationMapper.Map(shape["values"] as object[]), Map(shape["inherits"] as object[]), linkTargetName));
                }
                else // File
                {
                    return(GetFileShape(shape, linkTargetName, multipleOf, format, exclusiveMaximum, exclusiveMinimum, maximum, minimum, maxLength, minLength, pattern));
                }
            }

            if (shape.ContainsKey("raw") && shape["raw"] != null)
            {
                MapSchema(shape);
            }

            if (shape.ContainsKey("anyOf") && shape["anyOf"] is object[] anyOf && anyOf.Length > 0) // Union
            {
                return(new UnionShape(Map(shape["anyOf"] as object[]), DocumentationMapper.Map(shape["documentation"] as IDictionary <string, object>),
                                      XmlSerializerMapper.Map(shape["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(shape["examples"] as object[]),
                                      shape["id"] as string, shape["name"] as string, shape["displayName"] as string, shape["description"] as string, @default,
                                      StringEnumerationMapper.Map(shape["values"] as object[]), Map(shape["inherits"] as object[]), linkTargetName));
            }

            return(new AnyShape(DocumentationMapper.Map(shape["documentation"] as IDictionary <string, object>),
                                XmlSerializerMapper.Map(shape["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(shape["examples"] as object[]),
                                shape["id"] as string, shape["name"] as string, shape["displayName"] as string, shape["description"] as string, @default,
                                StringEnumerationMapper.Map(shape["values"] as object[]), Map(shape["inherits"] as object[]), linkTargetName));
        }
Exemplo n.º 4
0
        private static Shape GetFileShape(IDictionary <string, object> shape, string linkTargetName, int multipleOf, string format, string exclusiveMaximum, string exclusiveMinimum, string maximum, string minimum, int maxLength, int minLength, string pattern)
        {
            var fileTypes = StringEnumerationMapper.Map(shape["fileTypes"] as object[]);
            var @default  = Map(shape["default"] as IDictionary <string, object>);

            return(new FileShape(pattern, minLength, maxLength, minimum, maximum, exclusiveMinimum, exclusiveMaximum, format, multipleOf, fileTypes,
                                 DocumentationMapper.Map(shape["documentation"] as IDictionary <string, object>),
                                 XmlSerializerMapper.Map(shape["xmlSerialization"] as IDictionary <string, object>), ExampleMapper.Map(shape["examples"] as object[]),
                                 shape["id"] as string, shape["name"] as string, shape["displayName"] as string, shape["description"] as string, @default,
                                 StringEnumerationMapper.Map(shape["values"] as object[]), Map(shape["inherits"] as object[]), linkTargetName));
        }