File tree 2 files changed +23
-1
lines changed
src/Microsoft.OpenApi/Validations/Rules
test/Microsoft.OpenApi.Readers.Tests/V3Tests
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,31 @@ public static class OpenApiServerRules
26
26
context . CreateError ( nameof ( ServerRequiredFields ) ,
27
27
String . Format ( SRResource . Validation_FieldIsRequired , "url" , "server" ) ) ;
28
28
}
29
+
29
30
context . Exit ( ) ;
31
+ context . Enter ( "variables" ) ;
32
+ foreach ( var variable in server . Variables )
33
+ {
34
+ context . Enter ( variable . Key ) ;
35
+ ValidateServerVariableRequiredFields ( context , variable . Value ) ;
36
+ context . Exit ( ) ;
37
+ }
30
38
} ) ;
31
39
32
40
// add more rules
41
+
42
+ /// <summary>
43
+ /// Validate required fields in server variable
44
+ /// </summary>
45
+ private static void ValidateServerVariableRequiredFields ( IValidationContext context , OpenApiServerVariable item )
46
+ {
47
+ context . Enter ( "default" ) ;
48
+ if ( string . IsNullOrEmpty ( item . Default ) )
49
+ {
50
+ context . CreateError ( "ServerVariableMustHaveDefaultValue" ,
51
+ String . Format ( SRResource . Validation_FieldIsRequired , "default" , "variables" ) ) ;
52
+ }
53
+ context . Exit ( ) ;
54
+ }
33
55
}
34
56
}
Original file line number Diff line number Diff line change @@ -1413,7 +1413,7 @@ public void ParseBasicDocumentWithServerVariableShouldSucceed()
1413
1413
} ) ;
1414
1414
}
1415
1415
1416
- [ Fact ( Skip = "This test requires a validation for the Server variable object to be added." ) ]
1416
+ [ Fact ]
1417
1417
public void ParseBasicDocumentWithServerVariableAndNoDefaultShouldFail ( )
1418
1418
{
1419
1419
var openApiDoc = new OpenApiStringReader ( ) . Read ( """
You can’t perform that action at this time.
0 commit comments