Validation passing when nested required fields are missing

Issue #333 resolved
Treshauna Wright created an issue

Hello, I am using OpenAPI v3 and would like to throw validation errors when nested required fields are missing.

I have person object that looks like the following:
"personName": {
"prefixName": "Mr.",
"firstName": "John",
"middleName": "Louis",
"lastName": "Smith",
"suffixName": "Sr."
}

firstName and lastName are required fields and I have set personName as a nullable object because I don’t want the object is null but expected object error returned in this case.

This object is nested within another object. If I remove the entire personName object from my request, I would like to get back validation errors saying that firstName and lastName are required, but missing.

But validation is passing in this case.

Is there a way to get it to return errors in this case?

Comments (2)

  1. James Navin

    Hi Treshuana,

    From my understanding of your question, no - you won’t be able to get errors in that case. The reason being that (as defined) your request object matches the schema (e.g. if personName is nullable and you provide a null then the schema is valid).

    If personName is actually required on every request object then I would remove the nullable attribute, or ‘flatten’ the personName into the containing object using allOf (which will essentially merge the properties of the two objects).

    Hope this helps - feel free to re-open the issue if not.

  2. Log in to comment