Response Without Content Fails Validation
DapperMongoose opened this issue · 1 comments
Firstly, thanks for the great library!
I just tried upgrading to v0.0.40 of validator and I'm seeing a new failure.
My contract describes a couple of error states in responses with only a code and a description, such as:
'400':
description: this is the reason you would see this response code for this path/verb
When validating a response to an intentionally bad request I get the following validation error:
error validating: POST operation request response code '400' does not exist
I believe I have traced the error to the block that begins on line 47 within validate_body.go
// check if the response code is in the contract
foundResponse := operation.Responses.FindResponseByCode(httpCode)
if foundResponse != nil && foundResponse.Content != nil {
foundResponse finds the correct response with the correct description, however as Content is nil the if statement here fails. There is an else block below that that would examine the operation's default responses but that property is also nil so the validation fails with the incorrect error about the response code not existing.
Please let me know if you need any additional info/clarification, and thanks again!
Hi,
Glad you like the lib! This issue was a regression caused by a safety check being added.
This has been resolved in v0.0.42
and the behavior you experienced before should be restored.