API: rename util file to 'type_to_jsonschema'

This commit is contained in:
Johannes Kirschbauer
2025-08-18 18:39:28 +02:00
parent 287a303484
commit f82d18d649
3 changed files with 6 additions and 3 deletions

View File

@@ -16,7 +16,6 @@ from typing import (
get_type_hints,
)
from clan_lib.api.util import JSchemaTypeError
from clan_lib.async_run import get_current_thread_opkey
from clan_lib.errors import ClanError
@@ -204,7 +203,7 @@ API.register(get_system_file)
def to_json_schema(self) -> dict[str, Any]:
from typing import get_type_hints
from .util import type_to_dict
from .type_to_jsonschema import JSchemaTypeError, type_to_dict
api_schema: dict[str, Any] = {
"$comment": "An object containing API methods. ",

View File

@@ -211,6 +211,10 @@ def type_to_dict(
# If there's only one supported type, return it directly
return supported[0]
# TODO: it would maybe be better to return 'anyOf' this should work for typescript
# But is more correct for JSON Schema validation
# i.e. 42 would match all of "int | float" which would be an invalid value for that using "oneOf"
# If there are multiple supported types, return them as oneOf
return {
"oneOf": supported,