@@ -37,82 +37,78 @@ class SimpleDataClass:
3737 value : int = 42
3838
3939
40- def test_pydantic_model_with_aliases ():
41- """Test that Pydantic model schemas use field aliases when defined."""
42- schema = get_type_schema (EventArguments )
43-
44- assert schema ["type" ] == "object"
45- assert "properties" in schema
46-
47- # Check that aliases are used in property names
48- expected_properties = {
49- "UiPathEventConnector" ,
50- "UiPathEvent" ,
51- "UiPathEventObjectType" ,
52- "UiPathEventObjectId" ,
53- "UiPathAdditionalEventData" ,
54- }
55- actual_properties = set (schema ["properties" ].keys ())
56- assert actual_properties == expected_properties
57-
58- # All fields have defaults, so none should be required
59- assert schema ["required" ] == []
60-
61-
62- def test_pydantic_model_required_fields ():
63- """Test that required fields are correctly identified in Pydantic models."""
64- schema = get_type_schema (RequiredFieldsModel )
65-
66- assert schema ["type" ] == "object"
67- assert "properties" in schema
68-
69- # Check properties include both field names and aliases
70- expected_properties = {
71- "required_field" , # field name (no alias)
72- "optional_field" , # field name (no alias)
73- "AliasedRequired" , # alias
74- "AliasedOptional" , # alias
75- }
76- actual_properties = set (schema ["properties" ].keys ())
77- assert actual_properties == expected_properties
78-
79- # Check required fields (using aliases where defined)
80- expected_required = {"required_field" , "AliasedRequired" }
81- actual_required = set (schema ["required" ])
82- assert actual_required == expected_required
83-
84-
85- def test_dataclass_still_works ():
86- """Test that dataclass functionality is not broken."""
87- schema = get_type_schema (SimpleDataClass )
88-
89- assert schema ["type" ] == "object"
90- assert "properties" in schema
91-
92- # Dataclass should use field names (no alias support)
93- expected_properties = {"name" , "value" }
94- actual_properties = set (schema ["properties" ].keys ())
95- assert actual_properties == expected_properties
96-
97- # Field with default should not be required
98- assert schema ["required" ] == ["name" ]
99-
100-
101- def test_primitive_types ():
102- """Test that primitive type handling still works."""
103- assert get_type_schema (str ) == {"type" : "string" }
104- assert get_type_schema (int ) == {"type" : "integer" }
105- assert get_type_schema (float ) == {"type" : "number" }
106- assert get_type_schema (bool ) == {"type" : "boolean" }
107-
108-
109- def test_optional_types ():
110- """Test handling of Optional types."""
111- schema = get_type_schema (Optional [str ])
112- assert schema == {"type" : "string" } # Should unwrap Optional
113-
114-
115- def test_optional_union_types ():
116- """Test handling of Optional types."""
117- schema = get_type_schema (str | None )
118- assert schema == {"type" : "string" } # Should unwrap Optional
40+ class TestInputArgs :
41+ def test_pydantic_model_with_aliases (self ):
42+ """Test that Pydantic model schemas use field aliases when defined."""
43+ schema = get_type_schema (EventArguments )
44+
45+ assert schema ["type" ] == "object"
46+ assert "properties" in schema
47+
48+ # Check that aliases are used in property names
49+ expected_properties = {
50+ "UiPathEventConnector" ,
51+ "UiPathEvent" ,
52+ "UiPathEventObjectType" ,
53+ "UiPathEventObjectId" ,
54+ "UiPathAdditionalEventData" ,
55+ }
56+ actual_properties = set (schema ["properties" ].keys ())
57+ assert actual_properties == expected_properties
58+
59+ # All fields have defaults, so none should be required
60+ assert schema ["required" ] == []
61+
62+ def test_pydantic_model_required_fields (self ):
63+ """Test that required fields are correctly identified in Pydantic models."""
64+ schema = get_type_schema (RequiredFieldsModel )
65+
66+ assert schema ["type" ] == "object"
67+ assert "properties" in schema
68+
69+ # Check properties include both field names and aliases
70+ expected_properties = {
71+ "required_field" , # field name (no alias)
72+ "optional_field" , # field name (no alias)
73+ "AliasedRequired" , # alias
74+ "AliasedOptional" , # alias
75+ }
76+ actual_properties = set (schema ["properties" ].keys ())
77+ assert actual_properties == expected_properties
78+
79+ # Check required fields (using aliases where defined)
80+ expected_required = {"required_field" , "AliasedRequired" }
81+ actual_required = set (schema ["required" ])
82+ assert actual_required == expected_required
83+
84+ def test_dataclass_still_works (self ):
85+ """Test that dataclass functionality is not broken."""
86+ schema = get_type_schema (SimpleDataClass )
87+
88+ assert schema ["type" ] == "object"
89+ assert "properties" in schema
90+
91+ # Dataclass should use field names (no alias support)
92+ expected_properties = {"name" , "value" }
93+ actual_properties = set (schema ["properties" ].keys ())
94+ assert actual_properties == expected_properties
95+
96+ # Field with default should not be required
97+ assert schema ["required" ] == ["name" ]
98+
99+ def test_primitive_types (self ):
100+ """Test that primitive type handling still works."""
101+ assert get_type_schema (str ) == {"type" : "string" }
102+ assert get_type_schema (int ) == {"type" : "integer" }
103+ assert get_type_schema (float ) == {"type" : "number" }
104+ assert get_type_schema (bool ) == {"type" : "boolean" }
105+
106+ def test_optional_types (self ):
107+ """Test handling of Optional types."""
108+ response = get_type_schema (Optional [str ])
109+ assert response == {"type" : "string" } # Should unwrap Optional
110+
111+ def test_optional_union_types (self ):
112+ """Test handling of Optional types."""
113+ response = get_type_schema (str | None )
114+ assert response == {"type" : "string" } # Should unwrap Optional
0 commit comments