Validation passing when nested required fields are missing
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)
-
-
- changed status to resolved
- Log in to comment
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
isnullable
and you provide anull
then the schema is valid).If
personName
is actually required on every request object then I would remove thenullable
attribute, or ‘flatten’ thepersonName
into the containing object usingallOf
(which will essentially merge the properties of the two objects).Hope this helps - feel free to re-open the issue if not.