Skip to content

Is it possible to validate objects that lack a required property with a default value? #139

Answered by gregsdennis
dhalfageme asked this question in Q&A
Discussion options

You must be logged in to vote

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 in required), 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.

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by dhalfageme
Comment options

You must be logged in to vote
12 replies
@Relequestual
Comment options

@dhalfageme
Comment options

@Relequestual
Comment options

@dhalfageme
Comment options

@awwright
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants