コード例 #1
0
        public void ProcessMarkdownTocWithAbsoluteHrefShouldSucceed()
        {
            var content = @"
#[Topic1](/href1)
##Topic1.1
###[Topic1.1.1](/href1.1.1)
##[Topic1.2]()
#[Topic2](http://href.com)
";
            var toc = _fileCreator.CreateFile(content, FileType.MarkdownToc);
            FileCollection files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { toc });
            BuildDocument(files);

            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension));
            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath);
            var expectedModel = new TocItemViewModel
            {
                Items = new TocViewModel
                {
                    new TocItemViewModel
                    {
                        Name = "Topic1",
                        Href = "/href1",
                        TopicHref = "/href1",
                        Items = new TocViewModel
                        {
                            new TocItemViewModel
                            {
                                Name = "Topic1.1",
                                Items = new TocViewModel
                                {
                                    new TocItemViewModel
                                    {
                                        Name = "Topic1.1.1",
                                        Href = "/href1.1.1",
                                        TopicHref = "/href1.1.1"
                                    }
                                }
                            },
                            new TocItemViewModel
                            {
                                Name = "Topic1.2",
                                Href = string.Empty,
                                TopicHref = string.Empty
                            }
                        }
                    },
                    new TocItemViewModel
                    {
                        Name = "Topic2",
                        Href = "http://href.com",
                        TopicHref = "http://href.com"
                    }
                }
            };

            AssertTocEqual(expectedModel, model);
        }
コード例 #2
0
 public RestApiDocumentProcessorTest()
 {
     _outputFolder = GetRandomFolder();
     _inputFolder = GetRandomFolder();
     _templateFolder = GetRandomFolder();
     _defaultFiles = new FileCollection(Directory.GetCurrentDirectory());
     _defaultFiles.Add(DocumentType.Article, new[] { "TestData/contacts.json" }, "TestData/");
     _applyTemplateSettings = new ApplyTemplateSettings(_inputFolder, _outputFolder);
     _applyTemplateSettings.RawModelExportSettings.Export = true;
 }
コード例 #3
0
ファイル: MergeCommand.cs プロジェクト: vicancy/docfx
 private static FileCollection GetFileCollectionFromFileMapping(string baseDirectory, DocumentType type, FileMapping files)
 {
     var result = new FileCollection(baseDirectory);
     foreach (var mapping in files.Items)
     {
         result.Add(type, mapping.Files, mapping.SourceFolder, mapping.DestinationFolder);
     }
     return result;
 }
コード例 #4
0
        public void ProcessSwaggerShouldSucceed()
        {
            FileCollection files = new FileCollection(_defaultFiles);
            BuildDocument(files);

            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
            Assert.Equal("graph.windows.net/myorganization/Contacts/1.0", model.Uid);
            Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId);
            Assert.Equal(10, model.Children.Count);
            Assert.Equal("Hello world!", model.Metadata["meta"]);

            // Verify $ref in path
            var item0 = model.Children[0];
            Assert.Equal("graph.windows.net/myorganization/Contacts/1.0/get contacts", item0.Uid);
            Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">You can get a collection of contacts from your tenant.</p>\n", item0.Summary);
            Assert.Equal(1, item0.Parameters.Count);
            Assert.Equal("1.6", item0.Parameters[0].Metadata["default"]);
            Assert.Equal(1, item0.Responses.Count);
            Assert.Equal("200", item0.Responses[0].HttpStatusCode);

            // Verify tags of child
            var item0Tag = (JArray)(item0.Metadata["tags"]);
            Assert.NotNull(item0Tag);
            Assert.Equal("contacts", item0Tag[0]);
            var item1 = model.Children[1];
            var item2Tag = (JArray)(item1.Metadata["tags"]);
            Assert.NotNull(item2Tag);
            Assert.Equal("contacts", item2Tag[0]);
            Assert.Equal("pet store", item2Tag[1]);

            // Verify tags of root
            Assert.Equal(3, model.Tags.Count);
            var tag0 = model.Tags[0];
            Assert.Equal("contact", tag0.Name);
            Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">Everything about the <strong>contacts</strong></p>\n", tag0.Description);
            Assert.Equal("contact-bookmark", tag0.HtmlId);
            Assert.Equal(1, tag0.Metadata.Count);
            var externalDocs = (JObject)tag0.Metadata["externalDocs"];
            Assert.NotNull(externalDocs);
            Assert.Equal("Find out more", externalDocs["description"]);
            Assert.Equal("http://swagger.io", externalDocs["url"]);
            var tag1 = model.Tags[1];
            Assert.Equal("pet_store", tag1.HtmlId);

            // Verify path parameters
            // Path parameter applicable for get operation
            Assert.Equal(2, item1.Parameters.Count);
            Assert.Equal("object_id", item1.Parameters[0].Name);
            Assert.Equal("api-version", item1.Parameters[1].Name);
            Assert.Equal(true, item1.Parameters[1].Metadata["required"]);

            // Override ""api-version" parameters by $ref for patch operation
            var item2 = model.Children[2];
            Assert.Equal(3, item2.Parameters.Count);
            Assert.Equal("object_id", item2.Parameters[0].Name);
            Assert.Equal("api-version", item2.Parameters[1].Name);
            Assert.Equal(false, item2.Parameters[1].Metadata["required"]);

            // Override ""api-version" parameters by self definition for delete operation
            var item3 = model.Children[3];
            Assert.Equal(2, item3.Parameters.Count);
            Assert.Equal("object_id", item3.Parameters[0].Name);
            Assert.Equal("api-version", item3.Parameters[1].Name);
            Assert.Equal(false, item3.Parameters[1].Metadata["required"]);

            // When operation parameters is not set, inherit from th parameters for post operation
            var item4 = model.Children[4];
            Assert.Equal(1, item4.Parameters.Count);
            Assert.Equal("api-version", item4.Parameters[0].Name);
            Assert.Equal(true, item4.Parameters[0].Metadata["required"]);

            // When 'definitions' has direct child with $ref defined, should resolve it
            var item5 = model.Children[6];
            var parameter2 = (JObject)item5.Parameters[2].Metadata["schema"];
            Assert.Equal("string", parameter2["type"]);
            Assert.Equal("uri", parameter2["format"]);
            // Verify markup result of parameters
            Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The request body <em>contains</em> a single property that specifies the URL of the user or contact to add as manager.</p>\n",
                item5.Parameters[2].Description);
            Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\"><strong>uri</strong> description.</p>\n", 
                ((string)parameter2["description"]));
            Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">No Content. Indicates <strong>success</strong>. No response body is returned.</p>\n",
                item5.Responses[0].Description);
        }
コード例 #5
0
 public void ProcessSwaggerWithRemarksOverwriteShouldSucceed()
 {
     var files = new FileCollection(_defaultFiles);
     files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.remarks.md" });
     BuildDocument(files);
     {
         var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
         Assert.True(File.Exists(outputRawModelPath));
         var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
         Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.remarks.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Remarks content</p>\n", model.Remarks);
     }
 }
コード例 #6
0
        public void ProcessYamlTocWithTocHrefAndHomepageShouldFail()
        {

            var content = $@"
- name: Topic1
  tocHref: /Topic1/
  href: /Topic1/index.html
  homepage: /Topic1/index.html
";
            var toc = _fileCreator.CreateFile(content, FileType.YamlToc);
            FileCollection files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { toc });
            var e = Assert.Throws<DocumentException>(() => BuildDocument(files));
            Assert.Equal("TopicHref should be used to specify the homepage for /Topic1/ when tocHref is used.", e.Message);
        }
コード例 #7
0
 public void ProcessSwaggerWithNotPredefinedOverwriteShouldSucceed()
 {
     FileCollection files = new FileCollection(_defaultFiles);
     files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.not.predefined.md" });
     BuildDocument(files);
     {
         var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
         Assert.True(File.Exists(outputRawModelPath));
         var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
         Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.not.predefined.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content</p>\n", model.Metadata["not_defined_property"]);
         Assert.Null(model.Conceptual);
     }
 }
コード例 #8
0
        public void ProcessTocWithCircularReferenceShouldFail()
        {
            var referencedToc = _fileCreator.CreateFile($@"
- name: Topic
  href: TOC.md
", FileType.YamlToc, "sub1");
            var subToc = _fileCreator.CreateFile($@"
#Topic
##[ReferencedToc](Toc.yml)
", FileType.MarkdownToc, "sub1");
            var content = $@"
- name: Topic1
  href: {subToc}
";
            var toc = _fileCreator.CreateFile(content, FileType.YamlToc);
            FileCollection files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { toc, subToc });
            var e = Assert.Throws<DocumentException>(() => BuildDocument(files));
            Assert.Equal($"Circular reference to {StringExtension.ToDisplayPath(Path.GetFullPath(Path.Combine(_inputFolder, subToc)))} is found in {StringExtension.ToDisplayPath(Path.GetFullPath(Path.Combine(_inputFolder, referencedToc)))}", e.Message, true);
        }
コード例 #9
0
        public void ProcessSwaggerWithTagsOverwriteShouldSucceed()
        {
            FileCollection files = new FileCollection(_defaultFiles);
            files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.tags.md" });
            BuildDocument(files);

            {
                var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
                Assert.True(File.Exists(outputRawModelPath));
                var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
                var tag1 = model.Tags[0];
                Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.tags.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite <em>description</em> content</p>\n", tag1.Description);
                Assert.Null(tag1.Conceptual);
                var tag2 = model.Tags[1];
                Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">Access to Petstore orders</p>\n", tag2.Description);
                Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.tags.md\" sourcestartlinenumber=\"12\" sourceendlinenumber=\"12\">Overwrite <strong>conceptual</strong> content</p>\n", tag2.Conceptual);
            }
        }
コード例 #10
0
        public void ProcessSwaggerWithSimpleOverwriteShouldSucceed()
        {
            FileCollection files = new FileCollection(_defaultFiles);
            files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.simple.md" });
            BuildDocument(files);
            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
            Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.simple.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content</p>\n", model.Summary);
            Assert.Null(model.Conceptual);

            // Verify overwrite parameters
            var parametersForUpdate = model.Children.Single(c => c.OperationId == "update contact").Parameters;
            Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.simple.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new object_id description</p>\n",
                parametersForUpdate.Single(p => p.Name == "object_id").Description);
            Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.simple.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new bodyparam description</p>\n",
                parametersForUpdate.Single(p => p.Name == "bodyparam").Description);
        }
コード例 #11
0
        public void ProcessSwaggerWithXRefMap()
        {
            var files = new FileCollection(_defaultFiles);
            BuildDocument(files);

            var xrefMapPath = Path.Combine(Directory.GetCurrentDirectory(), _outputFolder, XRefArchive.MajorFileName);
            var xrefMap = YamlUtility.Deserialize<XRefMap>(xrefMapPath);

            Assert.NotNull(xrefMap.References);
            var rootItem = xrefMap.References[0];
            Assert.Equal("graph.windows.net/myorganization/Contacts/1.0", rootItem.Uid);
            Assert.Equal("Contacts", rootItem.Name);
            Assert.Equal("contacts.json", rootItem.Href);
            var childItem1 = xrefMap.References[1];
            Assert.Equal("graph.windows.net/myorganization/Contacts/1.0/delete contact", childItem1.Uid);
            Assert.Equal("delete contact", childItem1.Name);
            Assert.Equal("contacts.json", childItem1.Href);
            var tagItem1 = xrefMap.References[9];
            Assert.Equal("graph.windows.net/myorganization/Contacts/1.0/tag/contact", tagItem1.Uid);
            Assert.Equal("contact", tagItem1.Name);
            Assert.Equal("contacts.json", tagItem1.Href);
        }
コード例 #12
0
ファイル: FileCollection.cs プロジェクト: wanyi01/docfx
 public FileCollection(FileCollection collection) : this(collection.DefaultBaseDir)
 {
     _files = new List <FileAndType>(collection._files);
 }
コード例 #13
0
ファイル: FileCollection.cs プロジェクト: dotnet/docfx
 public FileCollection(FileCollection collection) : this(collection.DefaultBaseDir)
 {
     _files = new List<FileAndType>(collection._files);
 }
コード例 #14
0
        public void ProcessYamlTocWithFolderShouldSucceed()
        {
            var file1 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent);
            var file2 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub");
            var subToc = _fileCreator.CreateFile($@"
#[Topic]({Path.GetFileName(file2)})
", FileType.MarkdownToc, "sub");
            var content = $@"
- name: Topic1
  href: {file1}
  items:
    - name: Topic1.1
      href: {file1}
      homepage: {file2}
    - name: Topic1.2
      href: sub/
      homepage: {file1}
- name: Topic2
  href: sub/
";
            var toc = _fileCreator.CreateFile(content, FileType.YamlToc);
            FileCollection files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { file1, file2, toc, subToc });
            BuildDocument(files);
            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension));
            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath);
            var expectedModel = new TocItemViewModel
            {
                Items = new TocViewModel
                {
                    new TocItemViewModel
                    {
                        Name = "Topic1",
                        Href = file1,
                        TopicHref = file1,
                        Items = new TocViewModel
                        {
                            new TocItemViewModel
                            {
                                Name = "Topic1.1",
                                Href = file1, // For relative file, href keeps unchanged
                                Homepage = file2, // Homepage always keeps unchanged
                                TopicHref = file2,
                            },
                            new TocItemViewModel
                            {
                                Name = "Topic1.2",
                                Href = file1, // For relative folder, href should be overwritten by homepage
                                Homepage = file1,
                                TopicHref = file1,
                                TocHref = "sub/toc.md",
                            }
                        }
                    },
                    new TocItemViewModel
                    {
                        Name = "Topic2",
                        Href = file2,
                        TopicHref = file2,
                        TocHref = "sub/toc.md",
                    }
                }
            };

            AssertTocEqual(expectedModel, model);
        }
コード例 #15
0
 public void ProcessSwaggerWithInvalidOverwriteShouldFail()
 {
     FileCollection files = new FileCollection(_defaultFiles);
     files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.invalid.md" });
     Assert.Throws<DocumentException>(() => BuildDocument(files));
 }
コード例 #16
0
        public void ProcessYamlTocWithReferencedTocShouldSucceed()
        {
            var file1 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent);
            var file2 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub1");
            var file3 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub1/sub2");
            var referencedToc = _fileCreator.CreateFile($@"
- name: Topic
  href: {Path.GetFileName(file3)}
", FileType.YamlToc, "sub1/sub2");
            var subToc = _fileCreator.CreateFile($@"
#[Topic]({Path.GetFileName(file2)})
#[ReferencedToc](sub2/{Path.GetFileName(referencedToc)})
", FileType.MarkdownToc, "sub1");
            var content = $@"
- name: Topic1
  href: {file1}
  items:
    - name: Topic1.1
      href: {subToc}
      items:
        - name: Topic1.1.1
        - name: Topic1.1.2
    - name: Topic1.2
      href: {subToc}
      homepage: {file1}
- name: Topic2
  href: {referencedToc}
";
            var toc = _fileCreator.CreateFile(content, FileType.YamlToc);
            FileCollection files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { file1, file2, file3, toc, subToc });
            BuildDocument(files);
            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension));

            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath);
            var expectedModel = new TocItemViewModel
            {
                Items = new TocViewModel
                {
                    new TocItemViewModel
                    {
                        Name = "Topic1",
                        Href = file1,
                        TopicHref = file1,
                        Items = new TocViewModel
                        {
                            new TocItemViewModel
                            {
                                Name = "Topic1.1",
                                Href = null, // For referenced toc, the content from the referenced toc is expanded as the items of current toc, and href is cleared
                                TopicHref = null,
                                Items = new TocViewModel
                                {
                                    new TocItemViewModel
                                    {
                                        Name = "Topic",
                                        Href = file2,
                                        TopicHref = file2,
                                    },
                                    new TocItemViewModel
                                    {
                                        Name = "ReferencedToc",
                                        Items = new TocViewModel
                                        {
                                            new TocItemViewModel
                                            {
                                                Name = "Topic",
                                                Href = file3,
                                                TopicHref = file3,
                                            }
                                        }
                                    }
                                }
                            },
                            new TocItemViewModel
                            {
                                Name = "Topic1.2",
                                Href = file1, // For referenced toc, href should be overwritten by homepage
                                TopicHref = file1,
                                Homepage = file1,
                                Items = new TocViewModel
                                {
                                    new TocItemViewModel
                                    {
                                        Name = "Topic",
                                        Href = file2,
                                        TopicHref = file2,
                                    },
                                    new TocItemViewModel
                                    {
                                        Name = "ReferencedToc",
                                        Items = new TocViewModel
                                        {
                                            new TocItemViewModel
                                            {
                                                Name = "Topic",
                                                Href = file3,
                                                TopicHref = file3,
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new TocItemViewModel
                    {
                        Name = "Topic2",
                        Href = null,
                        Items = new TocViewModel
                        {
                            new TocItemViewModel
                            {
                                Name = "Topic",
                                Href = file3,
                                TopicHref = file3,
                            }
                        }
                    }
                }
            };

            AssertTocEqual(expectedModel, model);

            // Referenced TOC File should not exist
            var referencedTocPath = Path.Combine(_outputFolder, Path.ChangeExtension(subToc, RawModelFileExtension));
            Assert.False(File.Exists(referencedTocPath));
        }
コード例 #17
0
 public void ProcessSwaggerWithUnmergableOverwriteShouldSucceed()
 {
     FileCollection files = new FileCollection(_defaultFiles);
     files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.unmergable.md" });
     BuildDocument(files);
     {
         var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
         Assert.True(File.Exists(outputRawModelPath));
         var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
         Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId);
     }
 }
コード例 #18
0
        public void ProcessYamlTocWithTocHrefShouldSucceed()
        {
            var file1 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent);
            var file2 = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, "sub1/sub2");
            var referencedToc = _fileCreator.CreateFile($@"
- name: Topic
  href: {Path.GetFileName(file2)}
", FileType.YamlToc, "sub1/sub2");
            var content = $@"
- name: Topic1
  tocHref: /Topic1/
  topicHref: /Topic1/index.html
  items:
    - name: Topic1.1
      tocHref: /Topic1.1/
      topicHref: /Topic1.1/index.html
    - name: Topic1.2
      tocHref: /Topic1.2/
      topicHref: /Topic1.2/index.html
- name: Topic2
  tocHref: {referencedToc}
  topicHref: {file2}
";
            var toc = _fileCreator.CreateFile(content, FileType.YamlToc);
            FileCollection files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { file1, file2, toc, referencedToc });
            BuildDocument(files);
            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(toc, RawModelFileExtension));

            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<TocItemViewModel>(outputRawModelPath);
            var expectedModel = new TocItemViewModel
            {
                Items = new TocViewModel
                {
                    new TocItemViewModel
                    {
                        Name = "Topic1",
                        Href = "/Topic1/",
                        TocHref = "/Topic1/",
                        Homepage = "/Topic1/index.html",
                        TopicHref = "/Topic1/index.html",
                        Items = new TocViewModel
                        {
                            new TocItemViewModel
                            {
                                Name = "Topic1.1",
                                Href = "/Topic1.1/",
                                TocHref = "/Topic1.1/",
                                Homepage = "/Topic1.1/index.html",
                                TopicHref = "/Topic1.1/index.html",
                            },
                            new TocItemViewModel
                            {
                                Name = "Topic1.2",
                                Href = "/Topic1.2/",
                                TocHref = "/Topic1.2/",
                                Homepage = "/Topic1.2/index.html",
                                TopicHref = "/Topic1.2/index.html",
                            }
                        }
                    },
                    new TocItemViewModel
                    {
                        Name = "Topic2",
                        TocHref = referencedToc,
                        Href = referencedToc,
                        TopicHref = file2,
                        Homepage = file2,
                    }
                }
            };

            AssertTocEqual(expectedModel, model);
        }
コード例 #19
0
 public void ProcessSwaggerWithMultiUidOverwriteShouldSucceed()
 {
     var files = new FileCollection(_defaultFiles);
     files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.multi.uid.md" });
     files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.unmergable.md" });
     BuildDocument(files);
     {
         var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
         Assert.True(File.Exists(outputRawModelPath));
         var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);
         Assert.Equal("graph_windows_net_myorganization_Contacts_1_0", model.HtmlId);
         Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.multi.uid.md\" sourcestartlinenumber=\"6\" sourceendlinenumber=\"6\">Overwrite content1</p>\n", model.Conceptual);
         Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.multi.uid.md\" sourcestartlinenumber=\"13\" sourceendlinenumber=\"13\">Overwrite &quot;content2&quot;</p>\n", model.Summary);
         Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.multi.uid.md\" sourcestartlinenumber=\"20\" sourceendlinenumber=\"20\">Overwrite &#39;content3&#39;</p>\n", model.Metadata["not_defined_property"]);
     }
 }
コード例 #20
0
        public void RelativePathToTocShouldChooseTheNearestReferenceToc()
        {
            // |-toc.md
            // |-sub1
            //    |-sub2
            //       |-file
            //       |-sub3
            //           |-toc.md

            // Arrange
            const string fileFolder = "sub1/sub2";
            var file = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, fileFolder);
            var toc1 = _fileCreator.CreateFile($"#[Topic]({file})", FileType.MarkdownToc);
            const string toc2Folder = "sub1/sub2/sub3";
            var filePathRelativeToToc2 = ((RelativePath) file).MakeRelativeTo((RelativePath)toc2Folder);
            var toc2 = _fileCreator.CreateFile($"#[Same Topic]({filePathRelativeToToc2.FileName}", FileType.MarkdownToc, toc2Folder);
            var files = new FileCollection(_inputFolder);
            files.Add(DocumentType.Article, new[] { file, toc1, toc2 });

            // Act
            BuildDocument(files);

            // Assert
            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension(file, RawModelFileExtension));
            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<Dictionary<string, object>>(outputRawModelPath);
            Assert.Equal("../../toc.md", model["_tocRel"]);
        }
コード例 #21
0
        private void BuildDocument(FileCollection files)
        {
            var parameters = new DocumentBuildParameters
            {
                Files = files,
                OutputBaseDir = _outputFolder,
                ApplyTemplateSettings = _applyTemplateSettings,
                Metadata = new Dictionary<string, object>
                {
                    ["meta"] = "Hello world!",
                }.ToImmutableDictionary()
            };

            using (var builder = new DocumentBuilder(LoadAssemblies(), ImmutableArray<string>.Empty, null))
            {
                builder.Build(parameters);
            }
        }
コード例 #22
0
        private void BuildDocument(FileCollection files)
        {
            var parameters = new DocumentBuildParameters
            {
                Files = files,
                OutputBaseDir = _outputFolder,
                ApplyTemplateSettings = _applyTemplateSettings,
            };

            using (var builder = new DocumentBuilder(LoadAssemblies(), ImmutableArray<string>.Empty, null))
            {
                builder.Build(parameters);
            }
        }
コード例 #23
0
        public void ProcessSwaggerWithParametersOverwriteShouldSucceed()
        {
            var files = new FileCollection(_defaultFiles);
            files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.parameters.md" });
            BuildDocument(files);
            var outputRawModelPath = Path.Combine(_outputFolder, Path.ChangeExtension("contacts.json", RawModelFileExtension));
            Assert.True(File.Exists(outputRawModelPath));
            var model = JsonUtility.Deserialize<RestApiRootItemViewModel>(outputRawModelPath);

            // Verify overwrite parameters
            var parametersForUpdate = model.Children.Single(c => c.OperationId == "update contact").Parameters;
            Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.parameters.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new object_id description</p>\n",
                parametersForUpdate.Single(p => p.Name == "object_id").Description);
            var bodyparam = parametersForUpdate.Single(p => p.Name == "bodyparam");
            Assert.Equal("<p sourcefile=\"TestData/overwrite/rest.overwrite.parameters.md\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">The new bodyparam description</p>\n",
                bodyparam.Description);
            var properties = (JObject)(((JObject)bodyparam.Metadata["schema"])["properties"]);
            var objectType = properties["objectType"];
            Assert.Equal("string", objectType["type"]);
            Assert.Equal("this is overwrite objectType description", objectType["description"]);
            var errorDetail = properties["provisioningErrors"]["items"]["schema"]["properties"]["errorDetail"];
            Assert.Equal(JTokenType.Boolean, errorDetail["readOnly"].Type);
            Assert.Equal("false", errorDetail["readOnly"].ToString().ToLower());
            Assert.Equal("this is overwrite errorDetail description", errorDetail["description"]);

            var paramForUpdateManager = model.Children.Single(c => c.OperationId == "get contact memberOf links").Parameters.Single(p => p.Name == "bodyparam");
            var paramForAllOf = ((JObject)paramForUpdateManager.Metadata["schema"])["allOf"];
            // First allOf item is not overwritten
            Assert.Equal("<p sourcefile=\"TestData/contacts.json\" sourcestartlinenumber=\"1\" sourceendlinenumber=\"1\">original first allOf description</p>\n", paramForAllOf[0]["description"]);
            // Second allOf item is overwritten
            Assert.Equal("this is second overwrite allOf description", paramForAllOf[1]["description"]);
            Assert.Equal("this is overwrite location description", paramForAllOf[1]["properties"]["location"]["description"]);
            // Third allOf item's enum value is overwritten
            var paramForLevel = paramForAllOf[2]["properties"]["level"];
            Assert.Equal("this is overwrite level description", paramForLevel["description"]);
            Assert.Equal(3, paramForLevel["enum"].Count());
            Assert.Equal("Verbose", paramForLevel["enum"][0].ToString());
            Assert.Equal("Info", paramForLevel["enum"][1].ToString());
            Assert.Equal("Warning", paramForLevel["enum"][2].ToString());
        }