feat(classgen): add support for unknown types

This commit is contained in:
Johannes Kirschbauer
2025-05-20 15:49:56 +02:00
parent 7a0665da6d
commit 9eeae6e229
3 changed files with 32 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ Note: This module assumes the presence of other modules and classes such as `Cla
"""
import dataclasses
import inspect
from dataclasses import dataclass, fields, is_dataclass
from enum import Enum
from pathlib import Path
@@ -261,6 +262,10 @@ def construct_value(
return t(field_value) # type: ignore
if inspect.isclass(t) and t.__name__ == "Unknown":
# Return the field value as is
return field_value
msg = f"Unhandled field type {t} with value {field_value}"
raise ClanError(msg)

View File

@@ -1,5 +1,6 @@
import copy
import dataclasses
import inspect
import pathlib
from dataclasses import MISSING
from enum import EnumType
@@ -110,6 +111,12 @@ def type_to_dict(
if t is None:
return {"type": "null"}
if inspect.isclass(t) and t.__name__ == "Unknown":
# Empty should represent unknown
# We don't know anything about this type
# Nor about the nested fields, if there are any
return {}
if dataclasses.is_dataclass(t):
fields = dataclasses.fields(t)
properties = {}