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

            return(new PropertyShape(prop["path"] as string, ShapeMapper.Map(prop["range"] as IDictionary <string, object>),
                                     prop["inheritanceProvenance"] as string, ParameterMapperUtils.MapInt(prop, "minCount"), ParameterMapperUtils.MapInt(prop, "maxCount")));
        }
Exemplo n.º 2
0
        private static string GetLinkTargetName(IDictionary <string, object> shape)
        {
            if (!shape.ContainsKey("linkTarget"))
            {
                return(null);
            }

            var linkTarget     = shape["linkTarget"];
            var linkTargetName = ParameterMapperUtils.Map <string>((IDictionary <string, object>)linkTarget, "name");

            return(linkTargetName);
        }
Exemplo n.º 3
0
        internal static Settings Map(IDictionary <string, object> settings)
        {
            if (settings == null)
            {
                return(null);
            }

            return(new Settings(ParameterMapperUtils.Map <string>(settings, "requestTokenUri"), ParameterMapperUtils.Map <string>(settings, "authorizationUri"),
                                ParameterMapperUtils.Map <string>(settings, "tokenCredentialsUri"),
                                StringEnumerationMapper.Map(ParameterMapperUtils.Map <object[]>(settings, "signatures")),
                                ParameterMapperUtils.Map <string>(settings, "accessTokenUri"),
                                StringEnumerationMapper.Map(ParameterMapperUtils.Map <object[]>(settings, "authorizationGrants")),
                                ParameterMapperUtils.Map <string>(settings, "flow"), ScopeMapper.Map(ParameterMapperUtils.Map <object[]>(settings, "scopes")),
                                ParameterMapperUtils.Map <string>(settings, "name"), ParameterMapperUtils.Map <string>(settings, "in")));
        }
Exemplo n.º 4
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));
        }