(
    schema: Union[None, JsonSchema, List[JsonSchema]]
)
Given a schema, converts structured enumeration values (records, arrays)
    into schemas where the structured part is specified as a schema, with the
    primitive as the enum.
Given a schema, converts structured enumeration values (records, arrays)
    into schemas where the structured part is specified as a schema, with the
    primitive as the enum.
Given a schema converts structured enumeration values ( records arrays ) into schemas where the structured part is specified as a schema with the primitive as the enum .
def atomize_schema_enumerations(
    schema: Union[None, JsonSchema, List[JsonSchema]]
) -> None:
    """Given a schema, converts structured enumeration values (records, arrays)
    into schemas where the structured part is specified as a schema, with the
    primitive as the enum.
    """
    if schema is None:
        return
    if isinstance(schema, list):
        for s in schema:
            atomize_schema_enumerations(s)
        return

    if not isinstance(schema, dict):
        return

    for key in ["anyOf", "allOf", "oneOf", "items", "additionalProperties", "not"]:
        atomize_schema_enumerations(schema.get(key, None))

    for key in ["properties", "patternProperties", "dependencies"]:
        v = schema.get(key, None)
        if v is not None:
            atomize_schema_enumerations(list(v.values()))

    # now that we have handled all the recursive cases
    ev = schema.get("enum", None)
    if ev is not None:
        simple_evs: List[Any] = []
        complex_evs: List[JsonSchema] = []
        for e in ev:
            if isinstance(e, dict):
                required: List[str] = []
                props: Dict[str, JsonSchema] = {}
                for k, v in e.items():
                    required.append(k)
                    vs = {"enum": [v]}
                    atomize_schema_enumerations(vs)
                    props[k] = vs
                ds = {
                    "type": "object",
                    "additionalProperties": False,
                    "required": list(e.keys()),
                    "properties": props,
                }
                complex_evs.append(ds)

            elif isinstance(e, list) or isinstance(e, tuple):
                is_tuple = isinstance(e, tuple)
                items_len = len(e)
                items: List[JsonSchema] = []
                for v in e:
                    vs = {"enum": [v]}
                    atomize_schema_enumerations(vs)
                    items.append(vs)

                ls = {
                    "type": "array",
                    "items": items,
                    "additionalItems": False,
                    "minItems": items_len,
                    "maxItems": items_len,
                }
                if is_tuple:
                    ls["laleType"] = "tuple"
                complex_evs.append(ls)
            else:
                simple_evs.append(ev)

        if complex_evs:
            del schema["enum"]
            if simple_evs:
                complex_evs.append({"enum": simple_evs})
            if len(complex_evs) == 1:
                # special case, just update in place
                schema.update(complex_evs[0])
            else:
                schema["anyOf"] = complex_evs
def atomize_schema_enumerations ( schema : Union [ None , JsonSchema , List [ JsonSchema ] ] ) -> None : if schema is None : return if isinstance ( schema , list ) : for s in schema : atomize_schema_enumerations ( s ) return if not isinstance ( schema , dict ) : return for key in [ "anyOf" , "allOf" , "oneOf" , "items" , "additionalProperties" , "not" ] : atomize_schema_enumerations ( schema . get ( key , None ) ) for key in [ "properties" , "patternProperties" , "dependencies" ] : v = schema . get ( key , None ) if v is not None : atomize_schema_enumerations ( list ( v . values ( ) ) ) # now that we have handled all the recursive cases ev = schema . get ( "enum" , None ) if ev is not None : simple_evs : List [ Any ] = [ ] complex_evs : List [ JsonSchema ] = [ ] for e in ev : if isinstance ( e , dict ) : required : List [ str ] = [ ] props : Dict [ str , JsonSchema ] = { } for k , v in e . items ( ) : required . append ( k ) vs = { "enum" : [ v ] } atomize_schema_enumerations ( vs ) props [ k ] = vs ds = { "type" : "object" , "additionalProperties" : False , "required" : list ( e . keys ( ) ) , "properties" : props , } complex_evs . append ( ds ) elif isinstance ( e , list ) or isinstance ( e , tuple ) : is_tuple = isinstance ( e , tuple ) items_len = len ( e ) items : List [ JsonSchema ] = [ ] for v in e : vs = { "enum" : [ v ] } atomize_schema_enumerations ( vs ) items . append ( vs ) ls = { "type" : "array" , "items" : items , "additionalItems" : False , "minItems" : items_len , "maxItems" : items_len , } if is_tuple : ls [ "laleType" ] = "tuple" complex_evs . append ( ls ) else : simple_evs . append ( ev ) if complex_evs : del schema [ "enum" ] if simple_evs : complex_evs . append ( { "enum" : simple_evs } ) if len ( complex_evs ) == 1 : # special case, just update in place schema . update ( complex_evs [ 0 ] ) else : schema [ "anyOf" ] = complex_evs