Пример #1
0
        public Method Build(IDictionary <string, object> dynamicRaml, string defaultMediaType)
        {
            var method = new Method();

            new BasicInfoBuilder().Set(dynamicRaml, method);

            method.Verb    = dynamicRaml.ContainsKey("method") ? (string)dynamicRaml["method"] : null;
            method.Headers = dynamicRaml.ContainsKey("headers")
                                ? new ParametersBuilder(dynamicRaml["headers"] as IDictionary <string, object>).GetAsDictionary()
                                : new Dictionary <string, Parameter>();

            method.Responses = dynamicRaml.ContainsKey("responses")
                                ? new ResponsesBuilder(dynamicRaml["responses"] as IDictionary <string, object>).Get(defaultMediaType)
                                : new List <Response>();

            method.QueryParameters = dynamicRaml.ContainsKey("queryParameters")
                                ? new ParametersBuilder((IDictionary <string, object>)dynamicRaml["queryParameters"]).GetAsDictionary()
                                : null;

            method.Body = dynamicRaml.ContainsKey("body")
                ? new BodyBuilder((IDictionary <string, object>)dynamicRaml["body"]).GetAsDictionary(defaultMediaType)
                                : new Dictionary <string, MimeType>();

            method.BaseUriParameters = ParametersBuilder.GetUriParameters(dynamicRaml, "baseUriParameters");
            method.SecuredBy         = GetSecuredBy(dynamicRaml);
            method.Protocols         = ProtocolsBuilder.Get(dynamicRaml);
            method.Is          = GetIs(dynamicRaml);
            method.Description = dynamicRaml.ContainsKey("description") ? (string)dynamicRaml["description"] : null;

            method.Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml);

            return(method);
        }
Пример #2
0
        public IEnumerable <Response> Get(string defaultMediaType)
        {
            var list = new List <Response>();

            if (dynamicRaml == null)
            {
                return(list);
            }


            foreach (var pair in dynamicRaml)
            {
                var value = pair.Value as IDictionary <string, object>;
                if (value == null)
                {
                    continue;
                }

                list.Add(new Response
                {
                    Code        = pair.Key,
                    Description = value.ContainsKey("description") ? value["description"] as string : null,
                    Body        = GetBody(defaultMediaType, value),
                    Headers     = value.ContainsKey("headers")
                                                                                ? new ParametersBuilder(value["headers"] as IDictionary <string, object>).GetAsDictionary()
                                                                                : new Dictionary <string, Parameter>(),
                    Annotations = AnnotationsBuilder.GetAnnotations(value)
                });
            }
            return(list);
        }
Пример #3
0
        public async Task <RamlDocument> Build(IDictionary <string, object> dynamicRaml, string path = null)
        {
            var doc = new RamlDocument(dynamicRaml);

            doc.Types = new RamlTypesOrderedDictionary();

            if (dynamicRaml.ContainsKey("uses"))
            {
                var uses = dynamicRaml["uses"] as object[];
                if (uses != null)
                {
                    foreach (var library in uses)
                    {
                        var lib = library as IDictionary <string, object>;
                        if (lib != null)
                        {
                            string filePath;
                            if (path != null)
                            {
                                filePath = Path.Combine(Path.GetDirectoryName(path), (string)lib["value"]);
                            }
                            else
                            {
                                filePath = (string)lib["value"];
                            }

                            var preffix = (string)lib["key"];
                            var dynamic = await RamlParser.GetDynamicStructure(filePath);

                            TypeBuilder.AddTypes(doc.Types, (IDictionary <string, object>)dynamic, preffix);
                        }
                    }
                }
            }

            doc.BaseUri           = dynamicRaml.ContainsKey("baseUri") ? (string)dynamicRaml["baseUri"] : string.Empty;
            doc.Title             = dynamicRaml.ContainsKey("title") ? (string)dynamicRaml["title"] : string.Empty;
            doc.Version           = dynamicRaml.ContainsKey("version") ? (string)dynamicRaml["version"] : null;
            doc.MediaType         = dynamicRaml.ContainsKey("mediaType") ? (string)dynamicRaml["mediaType"] : null;
            doc.Documentation     = GetDocumentation(dynamicRaml);
            doc.BaseUriParameters = ParametersBuilder.GetUriParameters(dynamicRaml, "baseUriParameters");
            doc.SecuredBy         = GetSecuredBy(dynamicRaml);
            doc.Method            = dynamicRaml.ContainsKey("method") ? (string)dynamicRaml["method"] : null;
            doc.Protocols         = ProtocolsBuilder.Get(dynamicRaml);
            doc.SecuritySchemes   = GetSecuritySchemes(dynamicRaml, doc.MediaType);
            doc.ResourceTypes     = GetResourceTypes(dynamicRaml, doc.MediaType);
            doc.Traits            = GetTraits(dynamicRaml, doc.MediaType);
            doc.Schemas           = GetSchemas(dynamicRaml);
            doc.Resources         = GetResources(dynamicRaml, doc.ResourceTypes, doc.Traits, doc.MediaType);

            TypeBuilder.AddTypes(doc.Types, dynamicRaml);

            doc.AnnotationTypes = AnnotationTypesBuilder.Get(dynamicRaml);
            doc.Annotations     = AnnotationsBuilder.GetAnnotations(dynamicRaml);
            return(doc);
        }
Пример #4
0
        public DocumentationItem Build(IDictionary <string, object> dynamicRaml)
        {
            var item = new DocumentationItem
            {
                Title       = dynamicRaml.ContainsKey("title") ? (string)dynamicRaml["title"] : null,
                Content     = dynamicRaml.ContainsKey("content") ? (string)dynamicRaml["content"] : null,
                Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml)
            };

            return(item);
        }
 private static AnnotationType GetAnnotationType(IDictionary <string, object> annotationType)
 {
     return(new AnnotationType
     {
         AllowMultiple = annotationType.ContainsKey("allowMultiple") && Convert.ToBoolean(annotationType["allowMultiple"]),
         Description = annotationType.ContainsKey("description") ? (string)annotationType["description"] : string.Empty,
         DisplayName = annotationType.ContainsKey("displayName") ? (string)annotationType["displayName"] : string.Empty,
         Usage = annotationType.ContainsKey("usage") ? (string)annotationType["usage"] : string.Empty,
         Parameters = GetParameters(annotationType),
         AllowedTargets = GetAllowedTargets(annotationType),
         Annotations = AnnotationsBuilder.GetAnnotations(annotationType)
     });
 }
Пример #6
0
        public MimeType GetMimeType(object mimeType)
        {
            var value = mimeType as IDictionary <string, object>;

            if (value == null)
            {
                var schema = mimeType as string;
                return(!string.IsNullOrWhiteSpace(schema) ? new MimeType {
                    Schema = schema
                } : null);
            }

            if (value.ContainsKey("body") && value["body"] is IDictionary <string, object> )
            {
                value = (IDictionary <string, object>)value["body"];
            }

            RamlType ramlType = null;

            if (value.ContainsKey("type") && value.ContainsKey("properties"))
            {
                ramlType = TypeBuilder.GetRamlType(new KeyValuePair <string, object>("obj", mimeType));
            }

            if (value.ContainsKey("application/json"))
            {
                value = value["application/json"] as IDictionary <string, object>;
            }

            if (value.ContainsKey("type") && (value["type"] as IDictionary <string, object>) != null &&
                ((IDictionary <string, object>)value["type"]).ContainsKey("properties"))
            {
                ramlType = TypeBuilder.GetRamlType(new KeyValuePair <string, object>("obj", value["type"]));
            }

            return(new MimeType
            {
                Type = TypeExtractor.GetType(value),
                InlineType = ramlType,
                Description = value.ContainsKey("description") ? (string)value["description"] : null,
                Example = DynamicRamlParser.GetExample(value),
                Schema = GetSchema(value),
                FormParameters = value.ContainsKey("formParameters")
                                               ? GetParameters((IDictionary <string, object>)value["formParameters"])
                                               : null,
                Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml)
            });
        }
Пример #7
0
        public ResourceType Build(IDictionary <string, object> dynamicRaml, string defaultMediaType)
        {
            var resourceType = new ResourceType
            {
                Type        = TypeExtractor.Get(dynamicRaml),
                Is          = TypeExtractor.GetIs(dynamicRaml),
                Get         = GetVerb(dynamicRaml, "get", VerbType.GET, defaultMediaType),
                Post        = GetVerb(dynamicRaml, "post", VerbType.POST, defaultMediaType),
                Put         = GetVerb(dynamicRaml, "put", VerbType.PUT, defaultMediaType),
                Delete      = GetVerb(dynamicRaml, "delete", VerbType.DELETE, defaultMediaType),
                Patch       = GetVerb(dynamicRaml, "patch", VerbType.PATCH, defaultMediaType),
                Options     = GetVerb(dynamicRaml, "options", VerbType.OPTIONS, defaultMediaType),
                Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml)
            };

            return(resourceType);
        }
        public SecurityScheme Build(IDictionary <string, object> dynamicRaml, string defaultMediaType)
        {
            var securityScheme = new SecurityScheme();

            new BasicInfoBuilder().Set(dynamicRaml, securityScheme);

            securityScheme.DescribedBy = dynamicRaml.ContainsKey("describedBy")
                ? new SecuritySchemeDescriptorBuilder().Build((IDictionary <string, object>)dynamicRaml["describedBy"], defaultMediaType)
                                : null;

            securityScheme.Settings = dynamicRaml.ContainsKey("settings")
                                ? new SecuritySettingsBuilder().Build((IDictionary <string, object>)dynamicRaml["settings"])
                                : null;

            securityScheme.Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml);

            return(securityScheme);
        }
 public static void SetProperties(IDictionary <string, object> dynamicRaml, Parameter parameter)
 {
     parameter.Type        = TypeExtractor.GetType(dynamicRaml);
     parameter.Required    = dynamicRaml.ContainsKey("required") && Convert.ToBoolean(dynamicRaml["required"]);
     parameter.DisplayName = dynamicRaml.ContainsKey("displayName") ? (string)dynamicRaml["displayName"] : null;
     parameter.Description = dynamicRaml.ContainsKey("description") ? (string)dynamicRaml["description"] : null;
     parameter.Enum        = GetEnum(dynamicRaml);
     parameter.Repeat      = dynamicRaml.ContainsKey("repeat") && Convert.ToBoolean(dynamicRaml["repeat"]);
     parameter.Example     = dynamicRaml.ContainsKey("example") ? dynamicRaml["example"].ToString() : null;
     parameter.Default     = dynamicRaml.ContainsKey("default")
             ? (dynamicRaml["default"] != null ? dynamicRaml["default"].ToString() : null)
             : null;
     parameter.Pattern     = dynamicRaml.ContainsKey("pattern") ? (string)dynamicRaml["pattern"] : null;
     parameter.MinLength   = dynamicRaml.ContainsKey("minLength") ? Convert.ToInt32(dynamicRaml["minLength"]) : (int?)null;
     parameter.MaxLength   = dynamicRaml.ContainsKey("maxLength") ? Convert.ToInt32(dynamicRaml["maxLength"]) : (int?)null;
     parameter.Minimum     = dynamicRaml.ContainsKey("minimum") ? Convert.ToDecimal(dynamicRaml["minimum"]) : (decimal?)null;
     parameter.Maximum     = dynamicRaml.ContainsKey("maximum") ? Convert.ToDecimal(dynamicRaml["maximum"]) : (decimal?)null;
     parameter.Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml);
 }
Пример #10
0
        public Resource Build(IDictionary <string, object> dynamicRaml, IEnumerable <IDictionary <string, ResourceType> > resourceTypes,
                              IEnumerable <IDictionary <string, Method> > traits, string defaultMediaType)
        {
            var resource = new Resource();

            new BasicInfoBuilder().Set(dynamicRaml, resource);

            resource.RelativeUri       = dynamicRaml.ContainsKey("relativeUri") ? (string)dynamicRaml["relativeUri"] : null;
            resource.BaseUriParameters = ParametersBuilder.GetUriParameters(dynamicRaml, "baseUriParameters");
            resource.UriParameters     = ParametersBuilder.GetUriParameters(dynamicRaml, "uriParameters");
            resource.DisplayName       = dynamicRaml.ContainsKey("displayName") ? (string)dynamicRaml["displayName"] : null;
            resource.Protocols         = ProtocolsBuilder.Get(dynamicRaml);
            resource.Resources         = GetResources(dynamicRaml, resourceTypes, traits, defaultMediaType);

            resource.Methods = GetMethods(dynamicRaml, traits, defaultMediaType);

            resource.Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml);

            return(resource);
        }
Пример #11
0
        public RamlDocument Build(IDictionary <string, object> dynamicRaml)
        {
            var doc = new RamlDocument(dynamicRaml);

            doc.Types = new RamlTypesOrderedDictionary();

            if (dynamicRaml.ContainsKey("uses"))
            {
                var uses = dynamicRaml["uses"] as IDictionary <string, object>;
                if (uses != null)
                {
                    foreach (var library in uses)
                    {
                        var lib = library.Value as IDictionary <string, object>;
                        TypeBuilder.AddTypes(doc.Types, lib, library.Key);
                    }
                }
            }


            doc.BaseUri           = dynamicRaml.ContainsKey("baseUri") ? (string)dynamicRaml["baseUri"] : string.Empty;
            doc.Title             = dynamicRaml.ContainsKey("title") ? (string)dynamicRaml["title"] : string.Empty;
            doc.Version           = dynamicRaml.ContainsKey("version") ? (string)dynamicRaml["version"] : null;
            doc.MediaType         = dynamicRaml.ContainsKey("mediaType") ? (string)dynamicRaml["mediaType"] : null;
            doc.Documentation     = GetDocumentation(dynamicRaml);
            doc.BaseUriParameters = ParametersBuilder.GetUriParameters(dynamicRaml, "baseUriParameters");
            doc.SecuredBy         = GetSecuredBy(dynamicRaml);
            doc.Method            = dynamicRaml.ContainsKey("method") ? (string)dynamicRaml["method"] : null;
            doc.Protocols         = ProtocolsBuilder.Get(dynamicRaml);
            doc.SecuritySchemes   = GetSecuritySchemes(dynamicRaml, doc.MediaType);
            doc.ResourceTypes     = GetResourceTypes(dynamicRaml, doc.MediaType);
            doc.Traits            = GetTraits(dynamicRaml, doc.MediaType);
            doc.Schemas           = GetSchemas(dynamicRaml);
            doc.Resources         = GetResources(dynamicRaml, doc.ResourceTypes, doc.Traits, doc.MediaType);

            TypeBuilder.AddTypes(doc.Types, dynamicRaml);

            doc.AnnotationTypes = AnnotationTypesBuilder.Get(dynamicRaml);
            doc.Annotations     = AnnotationsBuilder.GetAnnotations(dynamicRaml);
            return(doc);
        }