@@ -43,15 +43,19 @@ func (v *responseBodyValidator) ValidateResponseBody(
43
43
// extract the response code from the response
44
44
httpCode := response .StatusCode
45
45
contentType := response .Header .Get (helpers .ContentTypeHeader )
46
+ codeStr := strconv .Itoa (httpCode )
46
47
47
48
// extract the media type from the content type header.
48
49
mediaTypeSting , _ , _ := helpers .ExtractContentType (contentType )
49
50
50
51
// check if the response code is in the contract
51
- foundResponse := operation .Responses .Codes .GetOrZero (fmt . Sprintf ( "%d" , httpCode ) )
52
+ foundResponse := operation .Responses .Codes .GetOrZero (codeStr )
52
53
if foundResponse == nil {
53
54
// check range definition for response codes
54
55
foundResponse = operation .Responses .Codes .GetOrZero (fmt .Sprintf ("%dXX" , httpCode / 100 ))
56
+ if foundResponse != nil {
57
+ codeStr = fmt .Sprintf ("%dXX" , httpCode / 100 )
58
+ }
55
59
}
56
60
57
61
if foundResponse != nil {
@@ -65,7 +69,6 @@ func (v *responseBodyValidator) ValidateResponseBody(
65
69
if foundResponse .Content != nil && orderedmap .Len (foundResponse .Content ) > 0 {
66
70
67
71
// content type not found in the contract
68
- codeStr := strconv .Itoa (httpCode )
69
72
validationErrors = append (validationErrors ,
70
73
errors .ResponseContentTypeNotFound (operation , request , response , codeStr , false ))
71
74
@@ -84,7 +87,6 @@ func (v *responseBodyValidator) ValidateResponseBody(
84
87
if operation .Responses .Default .Content != nil && orderedmap .Len (operation .Responses .Default .Content ) > 0 {
85
88
86
89
// content type not found in the contract
87
- codeStr := strconv .Itoa (httpCode )
88
90
validationErrors = append (validationErrors ,
89
91
errors .ResponseContentTypeNotFound (operation , request , response , codeStr , true ))
90
92
}
0 commit comments