|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Collections.Generic;
|
5 | 6 | using System.Globalization;
|
6 | 7 | using System.IO;
|
@@ -1670,27 +1671,6 @@ private static OpenApiDocument ParseInputFile(string filePath)
|
1670 | 1671 | return openApiDoc;
|
1671 | 1672 | }
|
1672 | 1673 |
|
1673 |
| - //[Fact] |
1674 |
| - //public void CopyConstructorForAdvancedDocumentWorks() |
1675 |
| - //{ |
1676 |
| - // // Arrange & Act |
1677 |
| - // var doc = new OpenApiDocument(AdvancedDocument); |
1678 |
| - |
1679 |
| - // var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets"; |
1680 |
| - // var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId; |
1681 |
| - // var responseSchemaTypeCopy = doc.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type = "object"; |
1682 |
| - // var advancedDocResponseSchemaType = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema.Type; |
1683 |
| - |
1684 |
| - // // Assert |
1685 |
| - // Assert.NotNull(doc.Info); |
1686 |
| - // Assert.NotNull(doc.Servers); |
1687 |
| - // Assert.NotNull(doc.Paths); |
1688 |
| - // Assert.Equal(2, doc.Paths.Count); |
1689 |
| - // Assert.NotNull(doc.Components); |
1690 |
| - // Assert.NotEqual(docOpId, advancedDocOpId); |
1691 |
| - // Assert.NotEqual(responseSchemaTypeCopy, advancedDocResponseSchemaType); |
1692 |
| - //} |
1693 |
| - |
1694 | 1674 | [Fact]
|
1695 | 1675 | public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat()
|
1696 | 1676 | {
|
@@ -1858,5 +1838,38 @@ public void OpenApiDocumentCopyConstructorWithAnnotationsSucceeds()
|
1858 | 1838 |
|
1859 | 1839 | Assert.NotEqual(baseDocument.Annotations["key1"], actualDocument.Annotations["key1"]);
|
1860 | 1840 | }
|
1861 |
| - } |
| 1841 | + |
| 1842 | + [Fact] |
| 1843 | + public void SerializeExamplesDoesNotThrowNullReferenceException() |
| 1844 | + { |
| 1845 | + OpenApiDocument doc = new OpenApiDocument |
| 1846 | + { |
| 1847 | + Paths = new OpenApiPaths |
| 1848 | + { |
| 1849 | + ["test"] = new OpenApiPathItem() |
| 1850 | + { |
| 1851 | + Operations = new Dictionary<OperationType, OpenApiOperation>() |
| 1852 | + { |
| 1853 | + [OperationType.Post] = new OpenApiOperation |
| 1854 | + { |
| 1855 | + RequestBody = new OpenApiRequestBody() |
| 1856 | + { |
| 1857 | + Content = |
| 1858 | + { |
| 1859 | + ["application/json"] = new OpenApiMediaType() |
| 1860 | + { |
| 1861 | + Examples = null, |
| 1862 | + }, |
| 1863 | + } |
| 1864 | + } |
| 1865 | + }, |
| 1866 | + } |
| 1867 | + }, |
| 1868 | + } |
| 1869 | + }; |
| 1870 | + |
| 1871 | + OpenApiJsonWriter apiWriter = new OpenApiJsonWriter(new StringWriter()); |
| 1872 | + doc.Invoking(d => d.SerializeAsV3(apiWriter)).Should().NotThrow(); |
| 1873 | + } |
| 1874 | + } |
1862 | 1875 | }
|
0 commit comments