We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The openapi3filter.ValidateRequest() function sometimes change request body but does not update GetBody() member of request.
We try this test code.
diff --git a/openapi3filter/validate_request_test.go b/openapi3filter/validate_request_test.go index 450ee59..8da550c 100644 --- a/openapi3filter/validate_request_test.go +++ b/openapi3filter/validate_request_test.go @@ -212,6 +212,12 @@ components: assert.Equal(t, contentLen, bodySize, "expect ContentLength %d to equal body size %d", contentLen, bodySize) bodyModified := originalBodySize != bodySize assert.Equal(t, bodyModified, tc.expectedModification, "expect request body modification happened: %t, expected %t", bodyModified, tc.expectedModification) + + validationInput.Request.Body, err = validationInput.Request.GetBody() + assert.NoError(t, err, "unable to re-generate body by GetBody(): %v", err) + body2, err := io.ReadAll(validationInput.Request.Body) + assert.NoError(t, err, "unable to read request body: %v", err) + assert.Equal(t, body, body2, "body by GetBody() is not matched") }) } }
Generate these error.
--- FAIL: TestValidateRequest (0.00s) --- FAIL: TestValidateRequest/Valid_request_without_certain_fields (0.00s) validate_request_test.go:220: Error Trace: /home/nishi/free5gc-deb/free5gc/lib/kin-openapi/openapi3filter/validate_request_test.go:220 Error: Not equal: expected: []byte{0x7b, 0x22, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x22, 0x53, 0x77, 0x65, 0x65, 0x74, 0x73, 0x22, 0x2c, 0x22, 0x73, 0x75, 0x62, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x22, 0x43, 0x68, 0x6f, 0x63, 0x6f, 0x6c, 0x61, 0x74, 0x65, 0x22, 0x7d} actual : []byte{0x7b, 0x22, 0x73, 0x75, 0x62, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x22, 0x3a, 0x22, 0x43, 0x68, 0x6f, 0x63, 0x6f, 0x6c, 0x61, 0x74, 0x65, 0x22, 0x7d} Diff: --- Expected +++ Actual @@ -1,5 +1,4 @@ -([]uint8) (len=47) { - 00000000 7b 22 63 61 74 65 67 6f 72 79 22 3a 22 53 77 65 |{"category":"Swe| - 00000010 65 74 73 22 2c 22 73 75 62 43 61 74 65 67 6f 72 |ets","subCategor| - 00000020 79 22 3a 22 43 68 6f 63 6f 6c 61 74 65 22 7d |y":"Chocolate"}| +([]uint8) (len=27) { + 00000000 7b 22 73 75 62 43 61 74 65 67 6f 72 79 22 3a 22 |{"subCategory":"| + 00000010 43 68 6f 63 6f 6c 61 74 65 22 7d |Chocolate"}| } Test: TestValidateRequest/Valid_request_without_certain_fields Messages: body by GetBody() is not matched FAIL FAIL github.com/getkin/kin-openapi/openapi3filter 0.012s FAIL
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
The openapi3filter.ValidateRequest() function sometimes change request body but does not update GetBody() member of request.
We try this test code.
Generate these error.
The text was updated successfully, but these errors were encountered: