Exemple #1
0
        public static WebApi Map(IDictionary <string, object> model)
        {
            if (model == null)
            {
                return(null);
            }

            var name        = model["name"] as string;
            var description = model["description"] as string;
            var host        = model["host"] as string;
            IEnumerable <string>   schemes     = StringEnumerationMapper.Map(model["schemes"] as object[]);
            IEnumerable <EndPoint> endPoints   = EndPointMapper.Map(model["endpoints"] as object[]);
            IEnumerable <string>   servers     = StringEnumerationMapper.Map(model["servers"] as object[]);
            IEnumerable <string>   accepts     = StringEnumerationMapper.Map(model["accepts"] as object[]);
            IEnumerable <string>   contentType = StringEnumerationMapper.Map(model["contentType"] as object[]);
            string       version        = model["version"] as string;
            string       termsOfService = model["termsOfService"] as string;
            Organization provider       = OrganizationMapper.Map(model["provider"] as IDictionary <string, object>);
            License      license        = LicenseMapper.Map(model["license"] as IDictionary <string, object>);
            IEnumerable <Documentation> documentations        = DocumentationMapper.Map(model["documentations"] as object[]);
            IEnumerable <Parameter>     baseUriParameters     = ParameterMapper.Map(model["baseUriParameters"] as object[]);
            IEnumerable <ParametrizedSecurityScheme> security = ParametrizedSecuritySchemeMapper.Map(model["security"] as object[]);

            return(new WebApi(name, description, host, schemes, endPoints, servers, accepts, contentType, version, termsOfService,
                              provider, license, documentations, baseUriParameters, security));
        }
Exemple #2
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));
        }
Exemple #3
0
        private static Operation Map(IDictionary <string, object> operation)
        {
            if (operation == null)
            {
                return(null);
            }

            return(new Operation(operation["method"] as string, operation["name"] as string, operation["description"] as string,
                                 operation["deprecated"] == null ? false : Convert.ToBoolean(operation["deprecated"]), operation["summary"] as string,
                                 DocumentationMapper.Map(operation["documentation"] as IDictionary <string, object>),
                                 StringEnumerationMapper.Map(operation["schemes"] as object[]), StringEnumerationMapper.Map(operation["accepts"] as object[]),
                                 StringEnumerationMapper.Map(operation["contentType"] as object[]), RequestMapper.Map(operation["request"] as IDictionary <string, object>),
                                 ResponseMapper.Map(operation["responses"] as object[]), SecuritySchemeMapper.Map(operation["security"] as object[])));
        }
Exemple #4
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)));
        }
Exemple #5
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));
        }