Skip to content

Commit f9fc4db

Browse files
committed
Add test to validate
1 parent 71de0e0 commit f9fc4db

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
using System.Threading;
1010
using FluentAssertions;
1111
using Microsoft.OpenApi.Any;
12+
using Microsoft.OpenApi.Exceptions;
1213
using Microsoft.OpenApi.Interfaces;
1314
using Microsoft.OpenApi.Models;
15+
using Microsoft.OpenApi.Readers.Interface;
1416
using Microsoft.OpenApi.Validations;
1517
using Microsoft.OpenApi.Validations.Rules;
1618
using Microsoft.OpenApi.Writers;
@@ -1355,5 +1357,15 @@ public void ValidateExampleShouldNotHaveDataTypeMismatch()
13551357
var warnings = diagnostic.Warnings;
13561358
Assert.False(warnings.Any());
13571359
}
1360+
1361+
[Fact]
1362+
public void ParseDocumetWithWrongReferenceTypeShouldReturnADiagnosticError()
1363+
{
1364+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "docWithWrongRef.json"));
1365+
_ = new OpenApiStreamReader().Read(stream, out var diagnostic);
1366+
1367+
diagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError> {
1368+
new( new OpenApiException("Invalid Reference Type 'Schema'.")) });
1369+
}
13581370
}
13591371
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"openapi":"3.0.0",
3+
"info":{
4+
"title":"some api",
5+
"description":"some description",
6+
"version": "1"
7+
},
8+
"servers":[{"url":"https://localhost"}],
9+
"paths":{
10+
"/count":{
11+
"get":{
12+
"responses":{
13+
"200":{
14+
"$ref":"#/components/schemas/count"
15+
},
16+
},
17+
}
18+
}
19+
},
20+
"components":{
21+
"schemas":{
22+
"count":{
23+
"type": "number"
24+
}
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)