Skip to content

Commit f8a775b

Browse files
committed
chore: adds missing yaml reader for readers tests
Signed-off-by: Vincent Biret <[email protected]>
1 parent 01398f0 commit f8a775b

24 files changed

+120
-92
lines changed

test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiDiagnosticTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class OpenApiDiagnosticTests
1818
[Fact]
1919
public async Task DetectedSpecificationVersionShouldBeV2_0()
2020
{
21-
var actual = await OpenApiDocument.LoadAsync("V2Tests/Samples/basic.v2.yaml");
21+
var actual = await OpenApiDocument.LoadAsync("V2Tests/Samples/basic.v2.yaml", SettingsFixture.ReaderSettings);
2222

2323
Assert.NotNull(actual.Diagnostic);
2424
Assert.Equal(OpenApiSpecVersion.OpenApi2_0, actual.Diagnostic.SpecificationVersion);
@@ -27,7 +27,7 @@ public async Task DetectedSpecificationVersionShouldBeV2_0()
2727
[Fact]
2828
public async Task DetectedSpecificationVersionShouldBeV3_0()
2929
{
30-
var actual = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml");
30+
var actual = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml", SettingsFixture.ReaderSettings);
3131

3232
Assert.NotNull(actual.Diagnostic);
3333
Assert.Equal(OpenApiSpecVersion.OpenApi3_0, actual.Diagnostic.SpecificationVersion);
@@ -43,6 +43,7 @@ public async Task DiagnosticReportMergedForExternalReferenceAsync()
4343
CustomExternalLoader = new ResourceLoader(),
4444
BaseUrl = new("fie://c:\\")
4545
};
46+
settings.AddYamlReader();
4647

4748
ReadResult result;
4849
result = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/OpenApiDiagnosticReportMerged/TodoMain.yaml", settings);

test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiStreamReaderTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public async Task StreamShouldCloseIfLeaveStreamOpenSettingEqualsFalse()
2020
{
2121
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
2222
var settings = new OpenApiReaderSettings { LeaveStreamOpen = false };
23+
settings.AddYamlReader();
2324
_ = await OpenApiDocument.LoadAsync(stream, settings: settings);
2425
Assert.False(stream.CanRead);
2526
}
@@ -29,6 +30,7 @@ public async Task StreamShouldNotCloseIfLeaveStreamOpenSettingEqualsTrue()
2930
{
3031
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
3132
var settings = new OpenApiReaderSettings { LeaveStreamOpen = true };
33+
settings.AddYamlReader();
3234
_ = await OpenApiDocument.LoadAsync(stream, settings: settings);
3335
Assert.True(stream.CanRead);
3436
}
@@ -43,7 +45,9 @@ public async Task StreamShouldNotBeDisposedIfLeaveStreamOpenSettingIsTrueAsync()
4345
memoryStream.Position = 0;
4446
var stream = memoryStream;
4547

46-
_ = await OpenApiDocument.LoadAsync(stream, settings: new OpenApiReaderSettings { LeaveStreamOpen = true });
48+
var settings = new OpenApiReaderSettings { LeaveStreamOpen = true };
49+
settings.AddYamlReader();
50+
_ = await OpenApiDocument.LoadAsync(stream, settings: settings);
4751
stream.Seek(0, SeekOrigin.Begin); // does not throw an object disposed exception
4852
Assert.True(stream.CanRead);
4953
}
@@ -59,7 +63,9 @@ public async Task StreamShouldReadWhenInitializedAsync()
5963
var stream = await httpClient.GetStreamAsync("20fe7a7b720a0e48e5842d002ac418b12a8201df/tests/v3.0/pass/petstore.yaml");
6064

6165
// Read V3 as YAML
62-
var result = await OpenApiDocument.LoadAsync(stream);
66+
var settings = new OpenApiReaderSettings();
67+
settings.AddYamlReader();
68+
var result = await OpenApiDocument.LoadAsync(stream, settings: settings);
6369
Assert.NotNull(result.Document);
6470
}
6571
}

test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/UnsupportedSpecVersionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public async Task ThrowOpenApiUnsupportedSpecVersionException()
1616
{
1717
try
1818
{
19-
_ = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/unsupported.v1.yaml");
19+
_ = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/unsupported.v1.yaml", SettingsFixture.ReaderSettings);
2020
}
2121
catch (OpenApiUnsupportedSpecVersionException exception)
2222
{

test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoW
2323
CustomExternalLoader = new MockLoader(),
2424
BaseUrl = new("file://c:\\")
2525
};
26+
settings.AddYamlReader();
2627

2728
var stream = new MemoryStream();
2829
var doc = """
@@ -52,6 +53,7 @@ public async Task LoadDocumentWithExternalReferenceShouldLoadBothDocumentsIntoWo
5253
CustomExternalLoader = new ResourceLoader(),
5354
BaseUrl = new("file://c:\\"),
5455
};
56+
settings.AddYamlReader();
5557

5658
ReadResult result;
5759
result = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiWorkspace/TodoMain.yaml", settings);

test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TryLoadReferenceV2Tests
2020
public async Task LoadParameterReference()
2121
{
2222
// Arrange
23-
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
23+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
2424
var reference = new OpenApiParameterReference("skipParam", result.Document);
2525

2626
// Assert
@@ -45,7 +45,7 @@ public async Task LoadParameterReference()
4545
[Fact]
4646
public async Task LoadSecuritySchemeReference()
4747
{
48-
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
48+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
4949

5050
var reference = new OpenApiSecuritySchemeReference("api_key_sample", result.Document);
5151

@@ -63,7 +63,7 @@ public async Task LoadSecuritySchemeReference()
6363
[Fact]
6464
public async Task LoadResponseReference()
6565
{
66-
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
66+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
6767

6868
var reference = new OpenApiResponseReference("NotFound", result.Document);
6969

@@ -83,7 +83,7 @@ public async Task LoadResponseReference()
8383
[Fact]
8484
public async Task LoadResponseAndSchemaReference()
8585
{
86-
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
86+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"), SettingsFixture.ReaderSettings);
8787
var reference = new OpenApiResponseReference("GeneralError", result.Document);
8888

8989
var expected = new OpenApiResponse
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Microsoft.OpenApi.Reader;
2+
3+
namespace Microsoft.OpenApi.Readers.Tests;
4+
public static class SettingsFixture
5+
{
6+
public static OpenApiReaderSettings ReaderSettings { get { var settings = new OpenApiReaderSettings(); settings.AddYamlReader() ; return settings; } }
7+
}

test/Microsoft.OpenApi.Readers.Tests/V2Tests/ComparisonTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public async Task EquivalentV2AndV3DocumentsShouldProduceEquivalentObjects(strin
2525
settings.AddYamlReader();
2626
using var streamV2 = Resources.GetStream(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
2727
using var streamV3 = Resources.GetStream(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
28-
var result1 = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
29-
var result2 = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
28+
var result1 = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"), SettingsFixture.ReaderSettings);
29+
var result2 = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"), SettingsFixture.ReaderSettings);
3030

3131
result2.Document.Should().BeEquivalentTo(result1.Document,
3232
options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
5151
exclusiveMinimum: false
5252
paths: {}
5353
""",
54-
"yaml");
54+
"yaml", SettingsFixture.ReaderSettings);
5555

5656
result.Document.Should().BeEquivalentTo(
5757
new OpenApiDocument
@@ -308,6 +308,7 @@ public async Task ParseDocumentWithDefaultContentTypeSettingShouldSucceed()
308308
{
309309
DefaultContentType = ["application/json"]
310310
};
311+
settings.AddYamlReader();
311312

312313
var actual = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithEmptyProduces.yaml"), settings);
313314
var mediaType = actual.Document.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content;

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void NoServer()
1919
paths: {}
2020
""";
2121

22-
var result = OpenApiDocument.Parse(input, "yaml");
22+
var result = OpenApiDocument.Parse(input, "yaml", SettingsFixture.ReaderSettings);
2323

2424
Assert.Empty(result.Document.Servers);
2525
}
@@ -37,7 +37,7 @@ public void JustSchemeNoDefault()
3737
- http
3838
paths: {}
3939
""";
40-
var result = OpenApiDocument.Parse(input, "yaml");
40+
var result = OpenApiDocument.Parse(input, "yaml", SettingsFixture.ReaderSettings);
4141

4242
Assert.Empty(result.Document.Servers);
4343
}
@@ -54,7 +54,7 @@ public void JustHostNoDefault()
5454
host: www.foo.com
5555
paths: {}
5656
""";
57-
var result = OpenApiDocument.Parse(input, "yaml");
57+
var result = OpenApiDocument.Parse(input, "yaml", SettingsFixture.ReaderSettings);
5858

5959
var server = result.Document.Servers.First();
6060
Assert.Single(result.Document.Servers);
@@ -79,6 +79,7 @@ public void NoBasePath()
7979
{
8080
BaseUrl = new("https://www.foo.com/spec.yaml")
8181
};
82+
settings.AddYamlReader();
8283

8384
var result = OpenApiDocument.Parse(input, "yaml", settings);
8485
var server = result.Document.Servers.First();
@@ -98,7 +99,7 @@ public void JustBasePathNoDefault()
9899
basePath: /baz
99100
paths: {}
100101
""";
101-
var result = OpenApiDocument.Parse(input, "yaml");
102+
var result = OpenApiDocument.Parse(input, "yaml", SettingsFixture.ReaderSettings);
102103

103104
var server = result.Document.Servers.First();
104105
Assert.Single(result.Document.Servers);
@@ -122,6 +123,7 @@ public void JustSchemeWithCustomHost()
122123
{
123124
BaseUrl = new("https://bing.com/foo")
124125
};
126+
settings.AddYamlReader();
125127

126128
var result = OpenApiDocument.Parse(input, "yaml", settings);
127129

@@ -147,6 +149,7 @@ public void JustSchemeWithCustomHostWithEmptyPath()
147149
{
148150
BaseUrl = new("https://bing.com")
149151
};
152+
settings.AddYamlReader();
150153

151154
var result = OpenApiDocument.Parse(input, "yaml", settings);
152155

@@ -171,6 +174,7 @@ public void JustBasePathWithCustomHost()
171174
{
172175
BaseUrl = new("https://bing.com")
173176
};
177+
settings.AddYamlReader();
174178

175179
var result = OpenApiDocument.Parse(input, "yaml", settings);
176180

@@ -195,6 +199,7 @@ public void JustHostWithCustomHost()
195199
{
196200
BaseUrl = new("https://bing.com")
197201
};
202+
settings.AddYamlReader();
198203

199204
var result = OpenApiDocument.Parse(input, "yaml", settings);
200205

@@ -220,6 +225,7 @@ public void JustHostWithCustomHostWithApi()
220225
{
221226
BaseUrl = new("https://dev.bing.com/api/description.yaml")
222227
};
228+
settings.AddYamlReader();
223229

224230
var result = OpenApiDocument.Parse(input, "yaml", settings);
225231
var server = result.Document.Servers.First();
@@ -246,6 +252,7 @@ public void MultipleServers()
246252
{
247253
BaseUrl = new("https://dev.bing.com/api")
248254
};
255+
settings.AddYamlReader();
249256

250257
var result = OpenApiDocument.Parse(input, "yaml", settings);
251258
var server = result.Document.Servers.First();
@@ -271,6 +278,7 @@ public void LocalHostWithCustomHost()
271278
{
272279
BaseUrl = new("https://bing.com")
273280
};
281+
settings.AddYamlReader();
274282

275283
var result = OpenApiDocument.Parse(input, "yaml", settings);
276284

@@ -296,6 +304,7 @@ public void InvalidHostShouldYieldError()
296304
{
297305
BaseUrl = new("https://bing.com")
298306
};
307+
settings.AddYamlReader();
299308

300309
var result = OpenApiDocument.Parse(input, "yaml", settings);
301310
Assert.Empty(result.Document.Servers);

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class OpenApiDocumentTests
2424
public async Task ParseDocumentWithWebhooksShouldSucceed()
2525
{
2626
// Arrange and Act
27-
var actual = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "documentWithWebhooks.yaml"));
27+
var actual = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "documentWithWebhooks.yaml"), SettingsFixture.ReaderSettings);
2828
var petSchema = new OpenApiSchemaReference("petSchema", actual.Document);
2929

3030
var newPetSchema = new OpenApiSchemaReference("newPetSchema", actual.Document);
@@ -219,7 +219,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
219219
public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
220220
{
221221
// Arrange && Act
222-
var actual = await OpenApiDocument.LoadAsync("V31Tests/Samples/OpenApiDocument/documentWithReusablePaths.yaml");
222+
var actual = await OpenApiDocument.LoadAsync("V31Tests/Samples/OpenApiDocument/documentWithReusablePaths.yaml", SettingsFixture.ReaderSettings);
223223

224224
var components = new OpenApiComponents
225225
{
@@ -429,7 +429,7 @@ public async Task ParseDocumentWithExampleInSchemaShouldSucceed()
429429
var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = false });
430430

431431
// Act
432-
var actual = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithExample.yaml"));
432+
var actual = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithExample.yaml"), SettingsFixture.ReaderSettings);
433433
actual.Document.SerializeAsV31(writer);
434434

435435
// Assert
@@ -440,7 +440,7 @@ public async Task ParseDocumentWithExampleInSchemaShouldSucceed()
440440
public async Task ParseDocumentWithPatternPropertiesInSchemaWorks()
441441
{
442442
// Arrange and Act
443-
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithPatternPropertiesInSchema.yaml"));
443+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithPatternPropertiesInSchema.yaml"), SettingsFixture.ReaderSettings);
444444
var actualSchema = result.Document.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;
445445

446446
var expectedSchema = new OpenApiSchema
@@ -497,7 +497,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks()
497497
public async Task ParseDocumentWithReferenceByIdGetsResolved()
498498
{
499499
// Arrange and Act
500-
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithReferenceById.yaml"));
500+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithReferenceById.yaml"), SettingsFixture.ReaderSettings);
501501

502502
var responseSchema = result.Document.Paths["/resource"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;
503503
var requestBodySchema = result.Document.Paths["/resource"].Operations[OperationType.Post].RequestBody.Content["application/json"].Schema;
@@ -520,6 +520,7 @@ public async Task ExternalDocumentDereferenceToOpenApiDocumentUsingJsonPointerWo
520520
LoadExternalRefs = true,
521521
BaseUrl = new(path),
522522
};
523+
settings.AddYamlReader();
523524

524525
// Act
525526
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalRefByJsonPointer.yaml"), settings);
@@ -541,10 +542,11 @@ public async Task ParseExternalDocumentDereferenceToOpenApiDocumentByIdWorks()
541542
LoadExternalRefs = true,
542543
BaseUrl = new(path),
543544
};
545+
settings.AddYamlReader();
544546

545547
// Act
546548
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalRefById.yaml"), settings);
547-
var doc2 = (await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalResource.yaml"))).Document;
549+
var doc2 = (await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalResource.yaml"), SettingsFixture.ReaderSettings)).Document;
548550

549551
var requestBodySchema = result.Document.Paths["/resource"].Operations[OperationType.Get].Parameters[0].Schema;
550552
result.Document.Workspace.RegisterComponents(doc2);
@@ -557,7 +559,7 @@ public async Task ParseExternalDocumentDereferenceToOpenApiDocumentByIdWorks()
557559
public async Task ParseDocumentWith31PropertiesWorks()
558560
{
559561
var path = Path.Combine(SampleFolderPath, "documentWith31Properties.yaml");
560-
var doc = (await OpenApiDocument.LoadAsync(path)).Document;
562+
var doc = (await OpenApiDocument.LoadAsync(path, SettingsFixture.ReaderSettings)).Document;
561563
var outputStringWriter = new StringWriter();
562564
doc.SerializeAsV31(new OpenApiYamlWriter(outputStringWriter));
563565
await outputStringWriter.FlushAsync();

0 commit comments

Comments
 (0)