@@ -7912,11 +7912,12 @@ def test_ref_nullable_with_constraint_creates_model(output_file: Path) -> None:
79127912 )
79137913
79147914
7915- def test_ref_nullable_with_extra_creates_model (output_file : Path ) -> None :
7916- """Test $ref + nullable: true + schema-affecting extras DOES create a merged model .
7915+ def test_ref_nullable_with_extra_uses_reference_directly (output_file : Path ) -> None :
7916+ """Test $ref + nullable: true + non- schema-affecting extras uses reference directly .
79177917
7918- When a property has $ref with nullable: true AND schema-affecting extras like
7919- 'if', 'then', 'else', it should merge the schemas and create a new model.
7918+ When a property has $ref with nullable: true AND extras that the tool cannot
7919+ structurally process (like 'if'), it should use the reference directly
7920+ instead of creating a merged model.
79207921 """
79217922 run_main_and_assert (
79227923 input_path = JSON_SCHEMA_DATA_PATH / "ref_nullable_with_extra.yaml" ,
@@ -8539,3 +8540,54 @@ def test_main_jsonschema_multiple_aliases_required_pydantic_v2(output_file: Path
85398540 "pydantic_v2.BaseModel" ,
85408541 ],
85418542 )
8543+
8544+
8545+ def test_ref_with_nonstandard_metadata (output_file : Path ) -> None :
8546+ """Test $ref with non-standard metadata fields preserves type information.
8547+
8548+ When $ref is combined with non-standard metadata like 'markdownDescription',
8549+ the reference type should be preserved instead of being replaced by the
8550+ underlying type. Non-standard fields are annotation-only and should not
8551+ trigger schema merging.
8552+ """
8553+ run_main_and_assert (
8554+ input_path = JSON_SCHEMA_DATA_PATH / "ref_with_nonstandard_metadata.json" ,
8555+ output_path = output_file ,
8556+ input_file_type = "jsonschema" ,
8557+ assert_func = assert_file_content ,
8558+ expected_file = "ref_with_nonstandard_metadata.py" ,
8559+ extra_args = ["--output-model-type" , "pydantic_v2.BaseModel" , "--use-annotated" ],
8560+ )
8561+
8562+
8563+ def test_ref_nullable_with_nonstandard_metadata (output_file : Path ) -> None :
8564+ """Test $ref + nullable: true with non-standard metadata uses reference directly.
8565+
8566+ When $ref is combined with nullable: true and non-standard metadata like
8567+ 'markdownDescription', the reference should be used directly with Optional
8568+ type annotation instead of creating a merged model.
8569+ """
8570+ run_main_and_assert (
8571+ input_path = JSON_SCHEMA_DATA_PATH / "ref_nullable_with_nonstandard_metadata.yaml" ,
8572+ output_path = output_file ,
8573+ input_file_type = "jsonschema" ,
8574+ assert_func = assert_file_content ,
8575+ expected_file = "ref_nullable_with_nonstandard_metadata.py" ,
8576+ extra_args = ["--output-model-type" , "pydantic_v2.BaseModel" , "--strict-nullable" ],
8577+ )
8578+
8579+
8580+ def test_ref_with_const (output_file : Path ) -> None :
8581+ """Test $ref + const triggers schema merging as const is schema-affecting.
8582+
8583+ When $ref is combined with 'const', the const keyword structurally affects
8584+ the generated type (producing Literal), so schema merging should occur.
8585+ """
8586+ run_main_and_assert (
8587+ input_path = JSON_SCHEMA_DATA_PATH / "ref_with_const.json" ,
8588+ output_path = output_file ,
8589+ input_file_type = "jsonschema" ,
8590+ assert_func = assert_file_content ,
8591+ expected_file = "ref_with_const.py" ,
8592+ extra_args = ["--output-model-type" , "pydantic_v2.BaseModel" , "--strict-nullable" ],
8593+ )
0 commit comments