From 23008d1f7330f3b35d08bc48bc88db031a3f3823 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 14 Oct 2025 12:06:04 +0200 Subject: [PATCH] openapi: Add a test for TypeAliasing --- .../clan_lib/api/type_to_jsonschema_test.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/pkgs/clan-cli/clan_lib/api/type_to_jsonschema_test.py b/pkgs/clan-cli/clan_lib/api/type_to_jsonschema_test.py index 511dee4fa..0ac57a616 100644 --- a/pkgs/clan-cli/clan_lib/api/type_to_jsonschema_test.py +++ b/pkgs/clan-cli/clan_lib/api/type_to_jsonschema_test.py @@ -320,3 +320,62 @@ def test_open_typed_dict() -> None: "additionalProperties": False, "required": ["name"], } + + +def test_type_alias() -> None: + # Test simple type alias + type UserId = int + + assert type_to_dict(UserId) == { + "type": "integer", + } + + # Test union type alias + type InputName = str | None + + assert type_to_dict(InputName) == { + "oneOf": [ + {"type": "string"}, + {"type": "null"}, + ], + } + + # Test complex type alias with list + type ServiceName = str + type ServiceNames = list[ServiceName] + + assert type_to_dict(ServiceNames) == { + "type": "array", + "items": {"type": "string"}, + } + + # Test type alias in a dataclass field + type Readme = str | None + + @dataclass + class ServiceReadmeCollection: + input_name: str | None + readmes: dict[str, Readme] + + assert type_to_dict(ServiceReadmeCollection) == { + "type": "object", + "properties": { + "input_name": { + "oneOf": [ + {"type": "string"}, + {"type": "null"}, + ], + }, + "readmes": { + "type": "object", + "additionalProperties": { + "oneOf": [ + {"type": "string"}, + {"type": "null"}, + ], + }, + }, + }, + "additionalProperties": False, + "required": ["input_name", "readmes"], + }