I have validate response enabled on all my routes, and noticed that when I use a schema with an allOf definition it throws $ should not have additional properties for every field.
Did some testing and found out that this is the problem. Fixable by replacing additionalProperties: false with unevaluatedProperties: false in a composition schema. I made a simple test showing this error and the fix here: RunKit
While debugging and testing I noticed that Tiny Validator has been last updated in 2017 and stopped maintenance. The tv4 error messages are also very unclear compared to newer packages like Ajv, but not sure if the Apidog team has any wishes to replace tv4?
Evans have you looked into this issue? It’s making somewhat complex schemes really hard to define as any use of composition is riddled with validation challenges (generating data works, but generates stuff the validator doesn’t approve of which was really confusing me for days until I found this post).
Evans This workaround also doesn’t seem to fully work for me. Could it be because I have some nested compositions? I have a oneOf inside of an allOf for example. I tried adding the unevaluatedProperties at the level of all the composition properties and this somewhat helps (less validation errors on a massive endpoint, but still some left). Any tips meep334 ?
So I’m clueless as to how to workaround this. It’s very annoying, especially as Apidog has written blog posts on how to use composition and everything, but the whole validation of those is simply broken
Nevermind, I’m actually an idiot. It just works, but my really complex JSON document had an actual schema error in it which I misread (the errors APIDog give you could be improved here too).
When you use allOf, the default value of additionalProperties for each child items will be set to fasle (Deny). If you set it to Default, no error will be reported by validation.
Alan thanks! By the way, how will this be implemented? If tv will be swapped out for ajv for example does that also mean we can use cool stuff like $data?
Mine is set to Default, but I guess because I have the Allow Objects to Have Additional Properties set to false, the default is Deny.
I could change it to Allow, but I want my response to be properly validated.
I made a couple of test cases to clarify my issue.
Two images per case, ordered respectively. I made four test cases, all calling a mock endpoint which returns {id: 1, description: 'demo', extra: true}. All four cases should return that the extra field is not allowed, except for case 3.
Object schema works properly with deny additionalProperties
getting one error for extra field
allOf with all objects set to deny, makes every field invalid
getting three errors, one for every field
allOf with all objects set to allow
no errors, but there is an extra field
Custom validator in post processor; additionalProperties is not defined
One error (for extra field) which is expected
Had to make the validator in the post-processor, because Apidog always defines the additionalProperties field to either true or false… (Dennis Laumen is right in saying that the unevaluatedProperties doesn’t do anything ) The field just has to not be there