jsonschema2dj/fields.py
def rationalize_type(name: str, sch: Dict, required: List[str]) -> Tuple[str, bool]:
    """the type is problematic especially with regards to enums and null"""
    null = name not in required

    if "type" in sch:
        _type = sch.get("type")
        if isinstance(_type, list):
            if len(sch["type"]) == 0 or len(_type) > 2 or len(_type) == 2 and "null" not in _type:
                raise ValueError(
                    "if type is a list it should either contain 1 element, or 2 where one is null"
                )
            if len(_type) == 1:
                _type = _type[0]
            else:
                null = True
                _type = next(x for x in _type if x != "null")
        return _type, null

    if sch.get("enum"):
        enums = sch.get("enum", [])
        if "null" in enums:
            enums.remove("null")
            null = True

        if all(isinstance(enum, int) for enum in enums):
            _type = "integer"
        elif all(isinstance(enum, str) for enum in enums):
            _type = "string"
        else:
            raise ValueError(
                "all values in an enum must be either all strings or all integers"
            )
        return _type, null

    raise ValueError(f"not possible to determine simple-field type for {name}")
the type is problematic especially with regards to enums and null
the type is problematic especially with regards to enums and null
the type is problematic especially with regards to enums and null
def rationalize_type(name: str, sch: Dict, required: List[str]) -> Tuple[str, bool]:
    null = name not in required
    if "type" in sch:
        _type = sch.get("type")
        if isinstance(_type, list):
            if len(sch["type"]) == 0 or len(_type) > 2 or len(_type) == 2 and "null" not in _type:
                raise ValueError(
                    "if type is a list it should either contain 1 element, or 2 where one is null"
                )
            if len(_type) == 1:
                _type = _type[0]
            else:
                null = True
                _type = next(x for x in _type if x != "null")
        return _type, null
    if sch.get("enum"):
        enums = sch.get("enum", [])
        if "null" in enums:
            enums.remove("null")
            null = True
        if all(isinstance(enum, int) for enum in enums):
            _type = "integer"
        elif all(isinstance(enum, str) for enum in enums):
            _type = "string"
        else:
            raise ValueError(
                "all values in an enum must be either all strings or all integers"
            )
        return _type, null
    raise ValueError(f"not possible to determine simple-field type for {name}")
def rationalize_type ( name : str , sch : Dict , required : List [ str ] ) -> Tuple [ str , bool ] : null = name not in required if "type" in sch : _type = sch . get ( "type" ) if isinstance ( _type , list ) : if len ( sch [ "type" ] ) == 0 or len ( _type ) > 2 or len ( _type ) == 2 and "null" not in _type : raise ValueError ( "if type is a list it should either contain 1 element, or 2 where one is null" ) if len ( _type ) == 1 : _type = _type [ 0 ] else : null = True _type = next ( x for x in _type if x != "null" ) return _type , null if sch . get ( "enum" ) : enums = sch . get ( "enum" , [ ] ) if "null" in enums : enums . remove ( "null" ) null = True if all ( isinstance ( enum , int ) for enum in enums ) : _type = "integer" elif all ( isinstance ( enum , str ) for enum in enums ) : _type = "string" else : raise ValueError ( "all values in an enum must be either all strings or all integers" ) return _type , null raise ValueError ( f"not possible to determine simple-field type for {name}" )
the type is problematic especially with regards to enums and null
the type is problematic especially with regards to enums and null
"""the type is problematic especially with regards to enums and null"""
name
str
sch
Dict
required
List[str]