Skip to content
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

Can't use 'oneof' for a list of complex elements #616

Open
McRussian opened this issue Mar 21, 2024 · 0 comments
Open

Can't use 'oneof' for a list of complex elements #616

McRussian opened this issue Mar 21, 2024 · 0 comments

Comments

@McRussian
Copy link

I have a list of values, the values can be of two different kinds. I have schemas for both types, and these schemas check for correctness. If the list contains values of only one type, then everything is fine, I can create a circuit that checks the correctness of such a list. But if I want to use objects of different types in one list, it doesn’t work.
For example, there are two schemes

SCHEMA_1 = {
        'name': {
            'type': 'string',
        },
        'value': {
            'type': 'integer',
            'min': 1,
            'max': 100,
        },
    }

SCHEMA_2 = {
        'name': {
            'type': 'string',
        },
        'value': {
            'type': 'string',
        },
    }

SCHEMA_LIST = {
        'value': {
        'type': 'list',
        'schema':  {
            'type': 'dict',
            'schema': SCHEMA_1,
        }
    }
}

SCHEMA_LIST2 = {
        'value': {
        'type': 'list',
        'schema':  {
            'type': 'dict',
            'schema':  SCHEMA_2,
        }
    }
}

print(v.validate({'value': [{'name': 'rr', 'value': 1}, {'name': 'dfdf', 'value': 3}]}, SCHEMA_LIST))
print(v.validate({'value': [{'name': 'rr', 'value': '1'}, {'name': 'dfdf', 'value': '3'}]}, SCHEMA_LIST2))

but if I try to write a circuit that needs to have different values for the elements of a list,

SCHEMA_COMMON = {
    'value': {
        'type': 'list',
        "schema" : {
            'type': 'dict',
            'schema': {
                'oneof': [SCHEMA_1, SCHEMA_2],
            }
        }
    }
}

print(v.validate({'value': [{'name': 'rr', 'value': 1}, {'name': 'dfdf', 'value': '3'}]}, SCHEMA_COMMON))

then various validation errors occur.

If you use variables of scalar types (int, string, etc.) as list elements, then everything works fine.

Is this a mistake, or am I drawing up the general diagram incorrectly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant