Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Tuples don't work properly #179

Open
csm10495 opened this issue Feb 14, 2022 · 0 comments
Open

Tuples don't work properly #179

csm10495 opened this issue Feb 14, 2022 · 0 comments

Comments

@csm10495
Copy link

Hey folks,

Say I have something like:

import dataclasses
from dataclasses_jsonschema import JsonSchemaMixin
from typing import Iterable, List, Set, Tuple, Union

@dataclasses.dataclass(frozen=True)
class Config(JsonSchemaMixin):
    tags: Tuple[Union[str, None]]

Config.from_dict({
    'tags': []
})

This leads to a raise like so:

ValidationError                           Traceback (most recent call last)
~site-packages/dataclasses_jsonschema/__init__.py in _validate(cls, data, validate_enums)
    488             else:
--> 489                 validate_func(data, cls.json_schema(validate_enums=validate_enums))
    490         except JsonSchemaValidationError as e:

~site-packages/jsonschema/validators.py in validate(instance, schema, cls, *args, **kwargs)
    933     if error is not None:
--> 934         raise error
    935

ValidationError: [] is too short

Failed validating 'minItems' in schema['properties']['tags']:
    {'items': [{'type': 'string'}],
     'maxItems': 1,
     'minItems': 1,
     'type': 'array'}

On instance['tags']:
    []

The above exception was the direct cause of the following exception:

ValidationError                           Traceback (most recent call last)
<ipython-input-3-400dc9903cd4> in <module>
      8
      9 Config.from_dict({
---> 10     'tags': []
     11 })

~site-packages/dataclasses_jsonschema/__init__.py in from_dict(cls, data, validate, validate_enums)
    506         non_init_values: Dict[str, Any] = {}
    507         if validate:
--> 508             cls._validate(data, validate_enums)
    509
    510         for f in cls._get_fields():

~site-packages/dataclasses_jsonschema/__init__.py in _validate(cls, data, validate_enums)
    489                 validate_func(data, cls.json_schema(validate_enums=validate_enums))
    490         except JsonSchemaValidationError as e:
--> 491             raise ValidationError(str(e)) from e
    492
    493     @classmethod

ValidationError: [] is too short

Failed validating 'minItems' in schema['properties']['tags']:
    {'items': [{'type': 'string'}],
     'maxItems': 1,
     'minItems': 1,
     'type': 'array'}

On instance['tags']:
    []

Using a list tends to pass validation (but then messes with the hashing since the are mutable)

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

No branches or pull requests

1 participant