Open alexkuz opened 7 years ago
Yeah, I think that makes sense. If the default value is set internally, then it makes sense to populate it. Otherwise, there's no reason I can think of to have a default value there.
So if default
is local, instantiate it, such that topmost default
overrides lower levels. If it's external, only do so if the property is required
. I think this will simplify the implementation and use, so 👍
I introduced
requiredOnly
earlier (https://github.com/dancasey/json-schema-default-instance/pull/1), but now I feel like it was a wrong way. I think there is a way to cover both options without additional flag.If we explicitly set default value in schema, like this:
or this:
it should resolve to:
{ prop: 1 }
.If there is an external schema with default value:
it should be ignored and resolved to
{ }
, unlessrequired
is set:Also, I guess default value for
object
type should override all property defaults, so:should be resolved to
{ prop1: 1 }
.What do you think?