jsf
jsf copied to clipboard
Use default values
Thanks for the tool!
Is there way to have it use default values from the schema where present, rather than faking values?
The only way to do this at the moment is to add
"$provider": "lambda: 'your default here'"
How would you ideally have it? Default would only be filled in if it was null so default gets set?
Great- thanks, I'll do that.
I'd like to be able to have default override the faking in all cases (even if the default is set to an empty value). Probably an atypical case though, maybe it could be an optional behaviour?
Happy to hear some proposals for the API to achieve it and what the behavior should achieve. If you could give some pseudo code examples and example schema + expected output?
Okay, so behaviour right now is like:
>>> from jsf import JSF
>>> test_schema
{'type': 'object', 'properties': {'test_field': {'type': 'string', 'default': 'default value'}}, 'required': ['test_field']}
>>> JSF(test_schema).generate()
{'test_field': 'quas placeat ipsum, libero culpa! esse officiis'}
So maybe what would be good would be something like:
>>> JSF(test_schema).generate(use_defaults = True)
{'test_field': 'default value'}
This is hard as the schema doesnt constrain it to only using the "default" otherwise it should be "const". This is because the "default" is a non restrictive keyword, unlike "type" or "enum"
Agree with the concept, but I'm not sure it will work for the overall package and peoples expectations.
Going to close this issue, but happy to consider other prooosals