hapi-openapi icon indicating copy to clipboard operation
hapi-openapi copied to clipboard

Default coercion in Validators.js returns undefined for empty payload

Open DanielAnfelt opened this issue 5 years ago • 2 comments

When hapi-openapi tries to validate the payload for an endpoint, and the payload is just an empty object, it will replace the empty object with an undefined instead. In my case, that meant that my object which didn't require any property to exist gave me a 422 response back.

The magic lines are currently 269 to 271 where:

            if (Util.isObject(data) && !Object.keys(data).length) {
                return undefined;
            }

I'm not sure what this is meant to accomplish, but it gave me a very unexpected 422 back.

DanielAnfelt avatar Nov 27 '19 19:11 DanielAnfelt

I am also having this issue. My assumption is that if the parameter is in body, the empty object should be returned rather than undefined.

Is this assumption correct?

Is the same true for other values of in?

tpburch avatar May 04 '20 17:05 tpburch

this issue is resolved with #178

dcharbonnier avatar May 27 '21 08:05 dcharbonnier