Is it possible to validate objects that lack a required property with a default value? #139
-
Hi!. Lets say I have this schema:
And this object.
The object doesn't validate using everit-org/json-schema java validor because it lacks of I would like to pass validation and build a new JSON object using default values for missing properties. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
The Thus, your instance doesn't validate because My suggestion would be to make |
Beta Was this translation helpful? Give feedback.
-
@gregsdennis Sorry for the out of scope response to your original answer So if I would like to do this default population, because it's a requirement, would I have to make some custom implementation that creates the properties when applying the new schema? There's no a workaround for this, right? I have hundreds of objects that I would like to evolve to new schema definitions and provide valid values when reading them |
Beta Was this translation helpful? Give feedback.
The
default
keyword doesn't perform any validation. It's an annotation-only keyword. This means that its purpose is to provide it's value to the application, and the application should determine what to do with that information.Thus, your instance doesn't validate because
id
is absent.My suggestion would be to make
id
optional (just don't list it inrequired
), which would allow your instance to pass. One the validation has passed, it should be accompanied by any annotations. From there, you can decide what to do with them.