@@ -43,15 +43,19 @@ func (v *responseBodyValidator) ValidateResponseBody(
4343 // extract the response code from the response
4444 httpCode := response .StatusCode
4545 contentType := response .Header .Get (helpers .ContentTypeHeader )
46+ codeStr := strconv .Itoa (httpCode )
4647
4748 // extract the media type from the content type header.
4849 mediaTypeSting , _ , _ := helpers .ExtractContentType (contentType )
4950
5051 // 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 )
5253 if foundResponse == nil {
5354 // check range definition for response codes
5455 foundResponse = operation .Responses .Codes .GetOrZero (fmt .Sprintf ("%dXX" , httpCode / 100 ))
56+ if foundResponse != nil {
57+ codeStr = fmt .Sprintf ("%dXX" , httpCode / 100 )
58+ }
5559 }
5660
5761 if foundResponse != nil {
@@ -65,7 +69,6 @@ func (v *responseBodyValidator) ValidateResponseBody(
6569 if foundResponse .Content != nil && orderedmap .Len (foundResponse .Content ) > 0 {
6670
6771 // content type not found in the contract
68- codeStr := strconv .Itoa (httpCode )
6972 validationErrors = append (validationErrors ,
7073 errors .ResponseContentTypeNotFound (operation , request , response , codeStr , false ))
7174
@@ -84,7 +87,6 @@ func (v *responseBodyValidator) ValidateResponseBody(
8487 if operation .Responses .Default .Content != nil && orderedmap .Len (operation .Responses .Default .Content ) > 0 {
8588
8689 // content type not found in the contract
87- codeStr := strconv .Itoa (httpCode )
8890 validationErrors = append (validationErrors ,
8991 errors .ResponseContentTypeNotFound (operation , request , response , codeStr , true ))
9092 }
0 commit comments