Merge pull request 'feat(docs,api): expose inventory.instances interface' (#3721) from hsjobeki/clan-core:inventory-services-1 into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3721
This commit is contained in:
hsjobeki
2025-05-20 15:29:14 +00:00
7 changed files with 166 additions and 56 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 = {}