@@ -1978,6 +1978,7 @@ def test_generate_with_config_object(output_file: Path) -> None:
19781978 GenerateConfig .model_rebuild (_types_namespace = {"StrictTypes" : StrictTypes , "UnionMode" : UnionMode })
19791979 config = GenerateConfig (
19801980 input_filename = "test.json" ,
1981+ output = output_file ,
19811982 output_model_type = DataModelType .PydanticV2BaseModel ,
19821983 use_schema_description = True ,
19831984 snake_case_field = True ,
@@ -1986,7 +1987,6 @@ def test_generate_with_config_object(output_file: Path) -> None:
19861987 )
19871988 generate (
19881989 input_ = '{"type": "object", "properties": {"userName": {"type": "string"}}}' ,
1989- output = output_file ,
19901990 config = config ,
19911991 )
19921992 content = output_file .read_text (encoding = "utf-8" )
@@ -1995,25 +1995,20 @@ def test_generate_with_config_object(output_file: Path) -> None:
19951995
19961996
19971997@pytest .mark .skipif (pydantic .VERSION < "2.0.0" , reason = "GenerateConfig requires Pydantic v2" )
1998- def test_generate_with_config_object_extra_template_data_override (output_file : Path ) -> None :
1999- """Test generate() with extra_template_data passed directly, overriding config."""
2000- from collections import defaultdict
2001-
1998+ def test_generate_with_config_and_kwargs_raises_error (output_file : Path ) -> None :
1999+ """Test generate() raises error when both config and kwargs are provided."""
20022000 from datamodel_code_generator .model .pydantic_v2 import UnionMode
20032001 from datamodel_code_generator .types import StrictTypes
20042002
20052003 GenerateConfig .model_rebuild (_types_namespace = {"StrictTypes" : StrictTypes , "UnionMode" : UnionMode })
20062004 config = GenerateConfig (
20072005 input_filename = "test.json" ,
20082006 output_model_type = DataModelType .PydanticV2BaseModel ,
2009- extra_template_data = {"Model" : {"config_key" : "config_value" }},
2010- )
2011- # Pass extra_template_data directly - this should override config value
2012- generate (
2013- input_ = '{"type": "object", "properties": {"name": {"type": "string"}}}' ,
2014- output = output_file ,
2015- config = config ,
2016- extra_template_data = defaultdict (dict , {"Model" : {"direct_key" : "direct_value" }}),
20172007 )
2018- content = output_file .read_text (encoding = "utf-8" )
2019- assert "class Model" in content
2008+ # Passing both config and kwargs should raise ValueError
2009+ with pytest .raises (ValueError , match = "Cannot specify both 'config' and keyword arguments" ):
2010+ generate (
2011+ input_ = '{"type": "object", "properties": {"name": {"type": "string"}}}' ,
2012+ output = output_file ,
2013+ config = config ,
2014+ )
0 commit comments