1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT license.
3
+
4
+ using System . Collections . Generic ;
5
+ using System . Linq ;
6
+ using Xunit ;
7
+
8
+ namespace Microsoft . OpenApi . Validations . Tests
9
+ {
10
+ public class OpenApiResponsesValidationTests
11
+ {
12
+ [ Theory ]
13
+ [ InlineData ( "200" ) ]
14
+ [ InlineData ( "404" ) ]
15
+ [ InlineData ( "500" ) ]
16
+ [ InlineData ( "1XX" ) ]
17
+ [ InlineData ( "2XX" ) ]
18
+ [ InlineData ( "3XX" ) ]
19
+ [ InlineData ( "4XX" ) ]
20
+ [ InlineData ( "5XX" ) ]
21
+ [ InlineData ( "1xx" ) ]
22
+ [ InlineData ( "2xx" ) ]
23
+ [ InlineData ( "3xx" ) ]
24
+ [ InlineData ( "4xx" ) ]
25
+ [ InlineData ( "5xx" ) ]
26
+ [ InlineData ( "default" ) ]
27
+ public void ValidateResponseKeyIsValid ( string responseKey )
28
+ {
29
+ // Arrange
30
+ var responses = new OpenApiResponses
31
+ {
32
+ [ responseKey ] = new OpenApiResponse { Description = "Test response" }
33
+ } ;
34
+
35
+ // Act
36
+ var errors = responses . Validate ( ValidationRuleSet . GetDefaultRuleSet ( ) ) ;
37
+
38
+ // Assert
39
+ Assert . Empty ( errors ) ;
40
+ }
41
+
42
+ [ Fact ]
43
+ public void ValidateMixedCaseResponseKeysAreAllowed ( )
44
+ {
45
+ // Arrange - Test the specific issue case mentioned in the bug report
46
+ var responses = new OpenApiResponses
47
+ {
48
+ [ "4xx" ] = new OpenApiResponse { Description = "Client error" } ,
49
+ [ "5XX" ] = new OpenApiResponse { Description = "Server error" } ,
50
+ [ "200" ] = new OpenApiResponse { Description = "Success" } ,
51
+ [ "default" ] = new OpenApiResponse { Description = "Default response" }
52
+ } ;
53
+
54
+ // Act
55
+ var errors = responses . Validate ( ValidationRuleSet . GetDefaultRuleSet ( ) ) ;
56
+
57
+ // Assert
58
+ Assert . Empty ( errors ) ;
59
+ }
60
+
61
+ [ Fact ]
62
+ public void ValidateLowercase4xxIsAccepted ( )
63
+ {
64
+ // Arrange - Test the specific reported issue
65
+ var responses = new OpenApiResponses
66
+ {
67
+ [ "4xx" ] = new OpenApiResponse { Description = "Client error" }
68
+ } ;
69
+
70
+ // Act
71
+ var errors = responses . Validate ( ValidationRuleSet . GetDefaultRuleSet ( ) ) ;
72
+
73
+ // Assert
74
+ Assert . Empty ( errors ) ;
75
+ }
76
+
77
+ [ Fact ]
78
+ public void ValidateLowercase5xxIsAccepted ( )
79
+ {
80
+ // Arrange - Test the specific reported issue
81
+ var responses = new OpenApiResponses
82
+ {
83
+ [ "5xx" ] = new OpenApiResponse { Description = "Server error" }
84
+ } ;
85
+
86
+ // Act
87
+ var errors = responses . Validate ( ValidationRuleSet . GetDefaultRuleSet ( ) ) ;
88
+
89
+ // Assert
90
+ Assert . Empty ( errors ) ;
91
+ }
92
+ }
93
+ }
0 commit comments