From f82d18d649cb892f79783e504c77982bac6e81e8 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Mon, 18 Aug 2025 18:39:28 +0200 Subject: [PATCH] API: rename util file to 'type_to_jsonschema' --- pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py | 2 +- pkgs/clan-cli/clan_lib/api/__init__.py | 3 +-- pkgs/clan-cli/clan_lib/api/{util.py => type_to_jsonschema.py} | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) rename pkgs/clan-cli/clan_lib/api/{util.py => type_to_jsonschema.py} (97%) diff --git a/pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py b/pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py index f264062a8..bb13ec460 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py +++ b/pkgs/clan-cli/clan_cli/tests/test_api_dataclass_compat.py @@ -7,7 +7,7 @@ from pathlib import Path from typing import cast from clan_lib.api import API -from clan_lib.api.util import JSchemaTypeError, type_to_dict +from clan_lib.api.type_to_jsonschema import JSchemaTypeError, type_to_dict from clan_lib.errors import ClanError diff --git a/pkgs/clan-cli/clan_lib/api/__init__.py b/pkgs/clan-cli/clan_lib/api/__init__.py index 1b1ed1f30..57f5f5b6c 100644 --- a/pkgs/clan-cli/clan_lib/api/__init__.py +++ b/pkgs/clan-cli/clan_lib/api/__init__.py @@ -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. ", diff --git a/pkgs/clan-cli/clan_lib/api/util.py b/pkgs/clan-cli/clan_lib/api/type_to_jsonschema.py similarity index 97% rename from pkgs/clan-cli/clan_lib/api/util.py rename to pkgs/clan-cli/clan_lib/api/type_to_jsonschema.py index c9082b5e2..b5d4379e3 100644 --- a/pkgs/clan-cli/clan_lib/api/util.py +++ b/pkgs/clan-cli/clan_lib/api/type_to_jsonschema.py @@ -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,