-
-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
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
validation adds default values to request body #639
Comments
@fenollp can you take a look? what do you think? |
Hi @fenollp (or anyone else maintaining this project). I suggest a fix to the issue above. In this fix, I keep the current behavior of adding default values to the request after the validation. Please use the fix (if all ok) and also add the validation test (just below the fix). In options.go I added a new option (SkipDefaultValueSet) :
In ValidateRequestBody function in validate_request.go, please add the following code:
instead of
Here is a test to validate the fix:
Thanks in advance, |
@fenollp adding default values into the request sends a lot of data over the wire which is not required. |
Could you share the code you're using that triggers that http2 error? I'm curious how you're getting a header error when that Also, I'd suggest to open pull requests whenever you want to prove something with code instead of pasting non-colored diffs. |
@fenollp We are using ValidateRequest on the client side. The request is created before the validation. Then the validation adds the defaults values . But the content length in the header is the same as before the validation. |
I see. So we can either update the content length or add a validation option that disables checking defaults. I believe the latter is what you're aiming for? |
Yes the latter. You can use my solution above: In options.go I added a new option (SkipDefaultValueSet) :
In ValidateRequestBody function in validate_request.go, please add the following code:
instead of opts = append(opts, openapi3.DefaultsSet(func() { defaultsSet = true })) |
Hi,
I am using the latest version of kin-openapi (v0.106.0).
In this latest version, kin-openapi adds default values to the request body even if they are not present.
For example, if the schema contains :
Then "prop1=false" will be added to the request body if not present.
This is wrong:
According to openapi specification https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schema-object:
Meaning that the consumer should make the assumptions, not the producer.
Adding these default values just create network overhead by making the requests larger without any need.
I am getting the following error because of that :
The code responsible for that is (in ValidateRequestBody function in validate_request.go):
I suggest either to remove this code, or make it optional (and the default behavior should be that no default values are added to the request body).
Thanks,
Oren
The text was updated successfully, but these errors were encountered: