@@ -81,14 +81,6 @@ public override void Visit(IOpenApiSchema schema)
81
81
82
82
private void ValidateSchemaReference ( OpenApiSchemaReference reference )
83
83
{
84
- // Trim off the leading "#/" as the context is already at the root of the document
85
- var segment =
86
- #if NET8_0_OR_GREATER
87
- $ "{ PathString [ 2 ..] } /$ref";
88
- #else
89
- PathString . Substring ( 2 ) + "/$ref" ;
90
- #endif
91
-
92
84
try
93
85
{
94
86
if ( reference . RecursiveTarget is not null )
@@ -99,7 +91,7 @@ private void ValidateSchemaReference(OpenApiSchemaReference reference)
99
91
}
100
92
catch ( InvalidOperationException ex )
101
93
{
102
- context . Enter ( segment ) ;
94
+ context . Enter ( GetSegment ( ) ) ;
103
95
context . CreateWarning ( ruleName , ex . Message ) ;
104
96
context . Exit ( ) ;
105
97
@@ -129,7 +121,7 @@ private void ValidateSchemaReference(OpenApiSchemaReference reference)
129
121
130
122
if ( ! isValid )
131
123
{
132
- context . Enter ( segment ) ;
124
+ context . Enter ( GetSegment ( ) ) ;
133
125
context . CreateWarning ( ruleName , string . Format ( SRResource . Validation_SchemaReferenceDoesNotExist , id ) ) ;
134
126
context . Exit ( ) ;
135
127
}
@@ -143,6 +135,17 @@ static bool IsValidSchemaReference(string id, JsonNode baseNode)
143
135
var pointer = new JsonPointer ( id . Replace ( "#/" , "/" ) ) ;
144
136
return pointer . Find ( baseNode ) ;
145
137
}
138
+
139
+ string GetSegment ( )
140
+ {
141
+ // Trim off the leading "#/" as the context is already at the root of the document
142
+ return
143
+ #if NET8_0_OR_GREATER
144
+ $ "{ PathString [ 2 ..] } /$ref";
145
+ #else
146
+ PathString . Substring ( 2 ) + "/$ref" ;
147
+ #endif
148
+ }
146
149
}
147
150
}
148
151
}
0 commit comments