Skip to content

Commit bcb0006

Browse files
committed
Fix dangling reference warning location
1 parent 56790ed commit bcb0006

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/datamodel_code_generator/parser/jsonschema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10460,7 +10460,7 @@ def _report_parse_diagnostics(self) -> None:
1046010460
f"Unresolved local $ref {ref!r} in {source}: JSON pointer was not found. "
1046110461
"Generated a fallback Any model; use --strict-refs to fail instead.",
1046210462
DanglingRefWarning,
10463-
stacklevel=3,
10463+
stacklevel=4,
1046410464
)
1046510465
self._dangling_refs.clear()
1046610466

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__init__.py

tests/main/test_error_messages.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def test_dangling_local_ref_warns_and_preserves_generated_output(
577577
capsys: pytest.CaptureFixture[str],
578578
) -> None:
579579
"""Default mode warns while retaining the legacy fallback model byte-for-byte."""
580-
with pytest.warns(DanglingRefWarning, match=r"Unresolved local \$ref.+dangling_local_ref\.json"):
580+
with pytest.warns(DanglingRefWarning, match=r"Unresolved local \$ref.+dangling_local_ref\.json") as warning_records:
581581
run_main_and_assert(
582582
input_path=MALFORMED_DATA_PATH / "dangling_local_ref.json",
583583
output_path=output_file,
@@ -589,6 +589,12 @@ def test_dangling_local_ref_warns_and_preserves_generated_output(
589589
assert_no_stderr=True,
590590
importable_module_name="generated_dangling_local_ref",
591591
)
592+
dangling_warnings = [warning for warning in warning_records if warning.category is DanglingRefWarning]
593+
assert_warnings_contain(dangling_warnings, "Unresolved local $ref")
594+
assert_output(
595+
"".join(f"{warning.filename.rsplit('/', 1)[-1]}\n" for warning in dangling_warnings),
596+
EXPECTED_MALFORMED_PATH / "dangling_ref_warning_location.txt",
597+
)
592598

593599

594600
def test_auto_detected_dangling_ref_keeps_source_context_and_generated_output(

0 commit comments

Comments
 (0)