Skip to content

Commit 5ad2f37

Browse files
committed
chore: adds a unit test of parsing the schema with relative reference using a parsing context
Signed-off-by: Vincent Biret <[email protected]>
1 parent e0bceaa commit 5ad2f37

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,32 @@ public async Task ShouldResolveRelativeSubReference()
298298
Assert.Equal(JsonSchemaType.String, seq2Property.Items.Items.Type);
299299
}
300300
[Fact]
301+
public async Task ShouldResolveRelativeSubReferenceUsingParsingContext()
302+
{
303+
// Arrange
304+
var filePath = Path.Combine(SampleFolderPath, "relativeSubschemaReference.json");
305+
using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
306+
var jsonNode = await JsonNode.ParseAsync(fs);
307+
var schemaJsonNode = jsonNode["components"]?["schemas"]?["Foo"];
308+
Assert.NotNull(schemaJsonNode);
309+
var diagnostic = new OpenApiDiagnostic();
310+
var parsingContext = new ParsingContext(diagnostic);
311+
parsingContext.StartObject("components");
312+
parsingContext.StartObject("schemas");
313+
parsingContext.StartObject("Foo");
314+
var document = new OpenApiDocument();
315+
316+
// Act
317+
var fooComponentSchema = parsingContext.ParseFragment<OpenApiSchema>(schemaJsonNode, OpenApiSpecVersion.OpenApi3_1, document);
318+
document.AddComponent("Foo", fooComponentSchema);
319+
var seq1Property = fooComponentSchema.Properties["seq1"];
320+
Assert.NotNull(seq1Property);
321+
var seq2Property = fooComponentSchema.Properties["seq2"];
322+
Assert.NotNull(seq2Property);
323+
Assert.Equal(JsonSchemaType.Array, seq2Property.Items.Type);
324+
Assert.Equal(JsonSchemaType.String, seq2Property.Items.Items.Type);
325+
}
326+
[Fact]
301327
public void ShouldFailToResolveRelativeSubReferenceFromTheObjectModel()
302328
{
303329
var document = new OpenApiDocument

0 commit comments

Comments
 (0)