-
Notifications
You must be signed in to change notification settings - Fork 35
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
Unable to generate object with minProperties or set minimum required properties. #113
Comments
jsf==0.11.2
|
If you want only true but it's still a bool in the schema you can use default or const not enum |
@ghandic none of these seems to work
|
Could you try adding required? |
@ghandic these properties should not be required, my goal is to use "anyOf" to make sure at least one of the properties exists with "True" value.
|
I think what you're wanting would be from jsf import JSF
parameters_schema = {
"type": "object",
"friendly_name": "Corporate Structure Changes",
"description": "Parameters for corporate structure changes",
"properties": {
"new_parent": {"type": "boolean", "default": True},
"new_subsidiary": {"type": "boolean", "default": True},
"new_sibling": {"type": "boolean", "default": True},
},
"minProperties": 1,
}
for _ in range(5):
print(JSF(parameters_schema).generate(use_defaults=True)) But we don't currently support minProperties, but this ensures only true values are set but not that at least one is set. |
@ghandic Thank you for the proposed solution which is actually generated that I need. The only problem with using In our project we use JSON schema for validation and I use JSF in our unit tests to randomly generate data for tests. Original JSON schema we use for validation:
Sorry for the misleading issue description. I hope now my task is clear. Thank you! |
You can use examples from jsf import JSF
parameters_schema = {
"type": "object",
"friendly_name": "Corporate Structure Changes",
"description": "Parameters for corporate structure changes",
"properties": {
"new_parent": {"type": "boolean", "examples": [True]},
"new_subsidiary": {"type": "boolean", "examples": [True]},
"new_sibling": {"type": "boolean", "examples": [True]},
},
}
for _ in range(5):
print(JSF(parameters_schema).generate(use_examples=True)) |
@ghandic
|
Ahh so the type isnt bool, you want it True all the time and the problem being when you set |
Could you have a squiz at the PR - see if that addresses your problem |
Hi @ghandic , sorry for the long reply. I double-check with my team about what we are trying to achieve. I added changes to your branch #115
as you can see third sample is invalid, but jsf still generates invalid data sometimes
It would be nice to have |
That's what the required does in the anyof/allof/oneof Min properties doesn't scale well as if you add another optional property it wouldn't work |
@ghandic here's schema we need without parameters_schema = {
"type": "object",
"friendly_name": "Corporate Structure Changes",
"description": "Parameters for corporate structure changes",
"properties": {
"new_parent": {"type": "boolean"},
"new_subsidiary": {"type": "boolean"},
"new_sibling": {"type": "boolean"},
},
"anyOf": [
{"properties": {"new_parent": {"const": True}}, "required": ["new_parent"]},
{"properties": {"new_subsidiary": {"const": True}}, "required": ["new_subsidiary"]},
{"properties": {"new_sibling": {"const": True}}, "required": ["new_sibling"]},
]
} and JSF generates data which cannot pass the validation. In [65]: JSF(parameters_schema).generate()
Out[65]: {}
In [81]: JSF(parameters_schema).generate()
Out[81]: {'new_parent': False, 'new_subsidiary': False}
In [82]: jsonschema.validate({"new_parent": False, "new_subsidiary": False},parameters_schema)
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[82], line 1
----> 1 jsonschema.validate({"new_parent": False, "new_subsidiary": False},parameters_schema)
File ~/.pyenv/versions/3.8.17/envs/zint-django/lib/python3.8/site-packages/jsonschema/validators.py:1332, in validate(instance, schema, cls, *args, **kwargs)
1330 error = exceptions.best_match(validator.iter_errors(instance))
1331 if error is not None:
-> 1332 raise error
ValidationError: True was expected
Failed validating 'const' in schema[0]['properties']['new_parent']:
{'const': True}
On instance['new_parent']:
False |
Hi, I'm trying to generate the following dict containing up to 3 items with
True
values:However, I don't see a correct JSON schema to make this done with JSF. When I try to use
anyOf
I could getFalse
. On the other hand, if I'm trying to useenum
JSF generates1
.jsf==0.8.0
, (withjsf==0.11.2
I get slightly different results, see comment)The text was updated successfully, but these errors were encountered: