-
Notifications
You must be signed in to change notification settings - Fork 276
Expand file tree
/
Copy pathOpenApiVisitorBaseTests.cs
More file actions
80 lines (74 loc) · 2.04 KB
/
OpenApiVisitorBaseTests.cs
File metadata and controls
80 lines (74 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.Generic;
using Xunit;
namespace Microsoft.OpenApi.Tests.Services;
public class OpenApiVisitorBaseTests
{
[Fact]
public void EncodesReservedCharacters()
{
// Given
var openApiDocument = new OpenApiDocument
{
Info = new()
{
Title = "foo",
Version = "1.2.2"
},
Paths = new()
{
},
Components = new()
{
Schemas = new Dictionary<string, IOpenApiSchema>()
{
["Pet~"] = new OpenApiSchema()
{
Type = JsonSchemaType.Object
},
["Pet/"] = new OpenApiSchema()
{
Type = JsonSchemaType.Object
},
}
}
};
var visitor = new LocatorVisitor();
// When
visitor.Visit(openApiDocument);
// Then
Assert.Equivalent(
new List<string>
{
"#/components/schemas/Pet~0",
"#/components/schemas/Pet~1"
}, visitor.Locations);
}
private class LocatorVisitor : OpenApiVisitorBase
{
public List<string> Locations { get; } = new List<string>();
public override void Visit(IOpenApiSchema openApiSchema)
{
Locations.Add(this.PathString);
}
public override void Visit(OpenApiComponents components)
{
Enter("schemas");
if (components.Schemas != null)
{
foreach (var schemaKvp in components.Schemas)
{
Enter(schemaKvp.Key);
this.Visit(schemaKvp.Value);
Exit();
}
}
Exit();
}
public override void Visit(OpenApiDocument doc)
{
Enter("components");
Visit(doc.Components);
Exit();
}
}
}