-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove optional flag in case of default
in schema.
#558
Comments
May be it's not good idea at all. From a server side view it's OK to remove optional flag because default value is injected at validation stage. |
Anyway, the option I've suggested earlier will be useful. For example, in our development process we use two separate ts-files (with defaults injected - for server and without - for clients) converted from one json schema. |
Just add them to the required lists? In the past I had experience that required was checked before default so didn't work necessarily but now I'm setting required and having default and it works even when not given (i.e. defaulted passes required check). The issue with the proposal indeed is what if |
|
Not really. Look — I use json schema files for:
Also:
You see? |
Don't judge before you try. So, your advice — don't use defaults in json schema, put this into code? Produce more imperative code instead of declarative? Funny. |
Of course. But it does make sense in context: would be param undefined or not (event if it's not required). So it's related to treating param is optional or not regardless it's not in |
For this narrow, selfish reason; I would be happiest with |
Correct me if I'm wrong, but nowadays the converter follows the strict rule: make prop optional if it's not in
required
list.But JSON Schema allows using key
default
. Of course, existence of the prop in real object depends on realization (e.g.: schema-based validator).I use
ajv
in my json-rpc server pipeline to validate arguments withuseDefaults:true
: it injects default values (defined in schema) in case of absent props.That's why I'd like to have optional flag removed from such types.
If you feel this is good idea, I can try to fork and make a pull request soon. I think this behavior should be optional, e.g.: `removeOptionalIfDefaultExists"
The text was updated successfully, but these errors were encountered: