Schema Composition Validation doesn't work with additionalProperties=false

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?

Apidog Europe - Version 2.5.21

Thanks for the feedback and we’ll look into this issue.

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 ?

Nevermind, the unevaluatedProperties did nothing, it was purely me playing around with the default setting of additionalProperties.

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).

Hi, the issue is reproducible and we are still investigating it.

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.


In the next version, the default value of additionalProperties for child items of “allOf” will NOT be “false”.

Evans awesome thanks!

Evans I’m often using composition in combination with schema references. Does this same issue occur in that situation?

You’re welcome, this problem has been fixed and will be updated in the next version.

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?

This is something that needs to be evaluated and I have fed it back to the product manager

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.
Bug_Demo.apidog.json|x
Bug_Demo.apidog.json|x

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.

  1. Object schema works properly with deny additionalProperties
  • getting one error for extra field
  1. allOf with all objects set to deny, makes every field invalid
  • getting three errors, one for every field
  1. allOf with all objects set to allow
  • no errors, but there is an extra field
  1. Custom validator in post processor; additionalProperties is not defined

Found out that in case 4 unevaluatedProperties: false is not necessary. It just needs additionalProperties to be undefined

Thanks for the feedback, I’ll try the cases you provided.

Thanks a lot! :slightly_smiling_face: