Skip to content

Unable to generate object with minProperties or set minimum required properties.  #113

Open
@danmash

Description

@danmash

Hi, I'm trying to generate the following dict containing up to 3 items with True values:

{'new_parent': True, 'new_subsidiary': True, 'new_sibling': True}

However, I don't see a correct JSON schema to make this done with JSF. When I try to use anyOf I could get False. On the other hand, if I'm trying to use enum JSF generates 1.

jsf==0.8.0, (with jsf==0.11.2 I get slightly different results, see comment)

In [1]: 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": {"enum": [True]}}},
   ...:             {"properties": {"new_subsidiary": {"enum": [True]}}},
   ...:             {"properties": {"new_sibling": {"enum": [True]}}},
   ...:         ]
   ...:     }

In [2]: from jsf import JSF
   ...: 

In [3]: JSF(parameters_schema).generate()
Out[3]: {}

In [4]: JSF(parameters_schema).generate()
Out[4]: {'new_parent': True, 'new_sibling': True}

In [5]: JSF(parameters_schema).generate()
Out[5]: {'new_subsidiary': True, 'new_sibling': False}

In [6]: JSF(parameters_schema).generate()
Out[6]: {'new_parent': False, 'new_subsidiary': False}

In [7]: JSF(parameters_schema).generate()
Out[7]: {'new_parent': True}

In [8]: parameters_schema = {
   ...:     "type": "object",
   ...:     "friendly_name": "Corporate Structure Changes",
   ...:     "description": "Parameters for corporate structure changes",
   ...:     "properties": {
   ...:         "new_parent": {"type": "boolean", "enum": [True]},
   ...:         "new_subsidiary": {"type": "boolean", "enum": [True]},
   ...:         "new_sibling": {"type": "boolean", "enum": [True]},
   ...:     },
   ...: }

In [9]: JSF(parameters_schema).generate()
Out[9]: {'new_subsidiary': 1, 'new_sibling': 1}

In [10]: JSF(parameters_schema).generate()
Out[10]: {'new_sibling': 1}

In [11]:     parameters_schema = {
    ...:         "type": "object",
    ...:         "friendly_name": "Corporate Structure Changes",
    ...:         "description": "Parameters for corporate structure changes",
    ...:         "properties": {
    ...:             "new_parent": {"type": "boolean", "anyOf": [{"enum": [True]}]},
    ...:             "new_subsidiary": {"type": "boolean", "anyOf": [{"enum": [True]}]},
    ...:             "new_sibling": {"type": "boolean",  "anyOf": [{"enum": [True]}]},
    ...:         }
    ...:     }

In [12]: JSF(parameters_schema).generate()
Out[12]: {'new_parent': False, 'new_subsidiary': True}

In [13]: JSF(parameters_schema).generate()
Out[13]: {'new_parent': True, 'new_sibling': True}

In [14]: JSF(parameters_schema).generate()
Out[14]: {'new_sibling': True}

In [15]: JSF(parameters_schema).generate()
Out[15]: {'new_parent': False, 'new_subsidiary': True}

In [16]:     parameters_schema = {
    ...:         "type": "object",
    ...:         "friendly_name": "Corporate Structure Changes",
    ...:         "description": "Parameters for corporate structure changes",
    ...:         "properties": {
    ...:             "new_parent": {"type": "boolean", "enum": [True]},
    ...:             "new_subsidiary": {"type": "boolean", "enum": [True]},
    ...:             "new_sibling": {"type": "boolean", "enum": [True]},
    ...:         }
    ...:     }

In [17]: JSF(parameters_schema).generate()
Out[17]: {'new_parent': 1, 'new_subsidiary': 1, 'new_sibling': 1}

In [18]:     parameters_schema = {
    ...:         "type": "object",
    ...:         "friendly_name": "Corporate Structure Changes",
    ...:         "description": "Parameters for corporate structure changes",
    ...:         "properties": {
    ...:             "new_parent": {"type": "boolean", "allOf": [{"enum": [True]}]},
    ...:             "new_subsidiary": {"type": "boolean", "allOf": [{"enum": [True]}]},
    ...:             "new_sibling": {"type": "boolean",  "allOf": [{"enum": [True]}]},
    ...:         }
    ...:     }

In [19]: JSF(parameters_schema).generate()
Out[19]: {'new_subsidiary': False, 'new_sibling': True}

In [20]: JSF(parameters_schema).generate()
Out[20]: {'new_subsidiary': False, 'new_sibling': True}

In [21]: JSF(parameters_schema).generate()
Out[21]: {'new_sibling': False}

In [22]:     parameters_schema = {
    ...:         "type": "object",
    ...:         "friendly_name": "Corporate Structure Changes",
    ...:         "description": "Parameters for corporate structure changes",
    ...:         "properties": {
    ...:             "new_parent": {"anyOf": [{"enum": [True], "type": "boolean"}]},
    ...:             "new_sibling": {"anyOf": [{"enum": [True], "type": "boolean"}]},
    ...:             "new_subsidiary": {"anyOf": [{"enum": [True], "type": "boolean"}]},
    ...:         }
    ...:     }

In [23]: JSF(parameters_schema).generate()
Out[23]: {'new_parent': 1, 'new_sibling': 1}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions