@@ -5591,6 +5591,74 @@ def test_main_jsonschema_enum_literal_type_alias_default(output_file: Path) -> N
55915591 )
55925592
55935593
5594+ @pytest .mark .skipif (
5595+ int (black .__version__ .split ("." )[0 ]) < 23 ,
5596+ reason = "Installed black doesn't support the new 'type' statement" ,
5597+ )
5598+ def test_main_jsonschema_ref_union_default_object (output_file : Path ) -> None :
5599+ """TypeAlias ref to union of BaseModels uses TypeAdapter for dict default (#3034)."""
5600+ run_main_and_assert (
5601+ input_path = JSON_SCHEMA_DATA_PATH / "ref_union_default_object.json" ,
5602+ output_path = output_file ,
5603+ input_file_type = None ,
5604+ assert_func = assert_file_content ,
5605+ expected_file = "ref_union_default_object.py" ,
5606+ extra_args = [
5607+ "--use-type-alias" ,
5608+ "--use-annotated" ,
5609+ "--target-python-version" ,
5610+ "3.12" ,
5611+ "--output-model-type" ,
5612+ "pydantic_v2.BaseModel" ,
5613+ ],
5614+ )
5615+
5616+
5617+ @pytest .mark .skipif (
5618+ int (black .__version__ .split ("." )[0 ]) < 23 ,
5619+ reason = "Installed black doesn't support the new 'type' statement" ,
5620+ )
5621+ def test_main_jsonschema_pydantic_v2_multi_model_union_default_object_type_alias (output_file : Path ) -> None :
5622+ """Inline union of multiple BaseModels uses TypeAdapter with --use-type-alias (#3035)."""
5623+ run_main_and_assert (
5624+ input_path = JSON_SCHEMA_DATA_PATH / "multi_model_union_default_object.json" ,
5625+ output_path = output_file ,
5626+ input_file_type = None ,
5627+ assert_func = assert_file_content ,
5628+ expected_file = "pydantic_v2_multi_model_union_default_object_type_alias.py" ,
5629+ extra_args = [
5630+ "--use-type-alias" ,
5631+ "--use-annotated" ,
5632+ "--target-python-version" ,
5633+ "3.12" ,
5634+ "--output-model-type" ,
5635+ "pydantic_v2.BaseModel" ,
5636+ ],
5637+ )
5638+
5639+
5640+ @pytest .mark .skipif (
5641+ int (black .__version__ .split ("." )[0 ]) < 23 ,
5642+ reason = "Installed black doesn't support the new 'type' statement" ,
5643+ )
5644+ def test_main_jsonschema_pydantic_v2_multi_model_union_default_object (output_file : Path ) -> None :
5645+ """Inline union of multiple BaseModels uses TypeAdapter without --use-type-alias (#3035)."""
5646+ run_main_and_assert (
5647+ input_path = JSON_SCHEMA_DATA_PATH / "multi_model_union_default_object.json" ,
5648+ output_path = output_file ,
5649+ input_file_type = None ,
5650+ assert_func = assert_file_content ,
5651+ expected_file = "pydantic_v2_multi_model_union_default_object.py" ,
5652+ extra_args = [
5653+ "--use-annotated" ,
5654+ "--target-python-version" ,
5655+ "3.12" ,
5656+ "--output-model-type" ,
5657+ "pydantic_v2.BaseModel" ,
5658+ ],
5659+ )
5660+
5661+
55945662@pytest .mark .cli_doc (
55955663 options = ["--type-mappings" ],
55965664 option_description = """Override default type mappings for schema formats.
0 commit comments