示例#1
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);
        }
示例#2
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);
        }