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