Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Default coercion in Validators.js returns undefined for empty payload #166

Closed
DanielAnfelt opened this issue Nov 27, 2019 · 2 comments
Closed

Comments

@DanielAnfelt
Copy link
Contributor

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.

@tpburch
Copy link
Contributor

tpburch commented May 4, 2020

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?

@dcharbonnier
Copy link
Contributor

this issue is resolved with #178

@stramel stramel closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants