You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This appears to still be a limitation of AJV. As noted in ajv-validator/ajv#1710 (comment) if the top level object does not exist the nested schema (and its defaults) will never be evaluated. One thing to try would be setting an empty object in a resolver before the validator runs:
Activity
daffl commentedon Oct 6, 2022
It appears this is the default AJV behaviour - to enable this, the
useDefaultsAjv option needs to be set. See https://ajv.js.org/options.html#usedefaults and https://dove.feathersjs.com/api/schema/schema.html#ajvprajwal497 commentedon Oct 7, 2022
It is already enabled and it does work on a simple structured schema with no sub or nested objects,
but does not work for sub documents.
daffl commentedon Oct 7, 2022
My guess is that it is because your nested object definition should look like this:
prajwal497 commentedon Oct 10, 2022
Whats the diffference?
daffl commentedon Oct 11, 2022
Yours is invalid JSON schema. An object definition (including nested ones) always needs to have a
prajwal497 commentedon Oct 12, 2022
Yes i may have missed that in the example but my code does have types for all sub documents (objects and arrays):
Updated Example:
or
daffl commentedon Oct 12, 2022
This appears to still be a limitation of AJV. As noted in ajv-validator/ajv#1710 (comment) if the top level object does not exist the nested schema (and its defaults) will never be evaluated. One thing to try would be setting an empty object in a resolver before the validator runs:
prajwal497 commentedon Oct 13, 2022
I will test this and get back to you