clan-cli: Expand type_to_dict to support NewType and tuple types in dataclasses
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import (
|
|||||||
Annotated,
|
Annotated,
|
||||||
Any,
|
Any,
|
||||||
Literal,
|
Literal,
|
||||||
|
NewType,
|
||||||
NotRequired,
|
NotRequired,
|
||||||
Required,
|
Required,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
@@ -187,6 +188,10 @@ def type_to_dict(
|
|||||||
raise JSchemaTypeError(msg)
|
raise JSchemaTypeError(msg)
|
||||||
return type_to_dict(type_map.get(t), scope, type_map)
|
return type_to_dict(type_map.get(t), scope, type_map)
|
||||||
|
|
||||||
|
if isinstance(t, NewType):
|
||||||
|
origtype = t.__supertype__
|
||||||
|
return type_to_dict(origtype, scope, type_map)
|
||||||
|
|
||||||
if hasattr(t, "__origin__"): # Check if it's a generic type
|
if hasattr(t, "__origin__"): # Check if it's a generic type
|
||||||
origin = get_origin(t)
|
origin = get_origin(t)
|
||||||
args = get_args(t)
|
args = get_args(t)
|
||||||
@@ -215,7 +220,7 @@ def type_to_dict(
|
|||||||
"oneOf": union_types,
|
"oneOf": union_types,
|
||||||
}
|
}
|
||||||
|
|
||||||
if origin in {list, set, frozenset}:
|
if origin in {list, set, frozenset, tuple}:
|
||||||
return {
|
return {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": type_to_dict(t.__args__[0], scope, type_map),
|
"items": type_to_dict(t.__args__[0], scope, type_map),
|
||||||
|
|||||||
Reference in New Issue
Block a user