Serde: fix enum type conversion, ensure roundtrip stability

This commit is contained in:
Johannes Kirschbauer
2025-01-03 16:31:25 +01:00
parent 0242d305c8
commit a42c758ab5
3 changed files with 41 additions and 8 deletions

View File

@@ -18,6 +18,8 @@ from typing import (
is_typeddict,
)
from clan_cli.api.serde import dataclass_to_dict
class JSchemaTypeError(Exception):
pass
@@ -257,7 +259,8 @@ def type_to_dict(
if type(t) is EnumType:
return {
"type": "string",
"enum": list(t.__members__),
# Construct every enum value and use the same method as the serde module for converting it into the same literal string
"enum": [dataclass_to_dict(t(value)) for value in t], # type: ignore
}
if t is Any:
msg = f"{scope} - Usage of the Any type is not supported for API functions. In: {scope}"