Skip to content

Add deprecation registry and docs#3188

Merged
koxudaxi merged 7 commits into
mainfrom
deprecation-registry-docs
May 25, 2026
Merged

Add deprecation registry and docs#3188
koxudaxi merged 7 commits into
mainfrom
deprecation-registry-docs

Conversation

@koxudaxi

@koxudaxi koxudaxi commented May 25, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added --list-deprecations CLI option to list registered deprecations and scheduled breaking changes (table, JSON, or Markdown).
  • Documentation

    • Added a comprehensive deprecations guide and updated CLI reference, quick/index listings, and several CLI option deprecation messages.
  • Tests

    • Added tests for --list-deprecations output and deprecation-docs/release-note generation.
  • Chores

    • Added tooling and CI/test env entries to build/verify deprecation docs and updated site navigation.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a central deprecation registry with rendering/warning helpers, a CLI flag --list-deprecations (table/json/markdown) to print registry data and exit, replaces scattered warnings with registry-driven warnings, and adds scripts, docs, and tests to generate and validate deprecation documentation.

Changes

Deprecation Infrastructure and CLI

Layer / File(s) Summary
Central Deprecation Registry
src/datamodel_code_generator/deprecations.py
Defines typed DeprecationKind, DeprecationStatus, and DeprecationFormat; a frozen Deprecation dataclass; populates DEPRECATIONS; and adds iter_deprecations(), get_deprecation(), warn_deprecated(), deprecation_message(), serialization, and rendering functions (table/json/markdown) plus release-note rendering.
CLI Integration for Listing Deprecations
src/datamodel_code_generator/arguments.py, src/datamodel_code_generator/cli_options.py, src/datamodel_code_generator/__main__.py
Adds `--list-deprecations [table
Standardized Deprecation Warnings
src/datamodel_code_generator/format.py, src/datamodel_code_generator/parser/jsonschema.py, src/datamodel_code_generator/parser/openapi.py, src/datamodel_code_generator/util.py
Replaces direct warnings.warn(...) calls with warn_deprecated(...) at multiple call sites (formatting defaults, JSON Schema remote $ref and items-array, OpenAPI nullable/validation, YAML boolean casing), preserving structured messages and categories.
Build Script and Registry Validation
scripts/build_deprecation_docs.py, scripts/build_cli_docs.py, tests/test_deprecations.py, tests/test_build_deprecation_docs_script.py
Adds scripts/build_deprecation_docs.py to generate/validate docs/deprecations.md and print release-note snippets; registers manual option description for --list-deprecations; adds tests validating registry metadata, JSON/table/Markdown rendering, release-note filtering, and warn_deprecated() behavior.
CLI Tests and Configuration
tests/main/test_main_general.py, pyproject.toml, tox.ini
Adds integration tests for --list-deprecations (human and JSON output), updates pyproject.toml pytest filterwarnings to ignore a known deprecation (--allow-extra-fields), and adds a testenv:deprecation-docs plus generated-docs step in tox.ini.
Documentation and Site Navigation
docs/cli-reference/index.md, docs/cli-reference/manual/list-deprecations.md, docs/cli-reference/model-customization.md, docs/cli-reference/openapi-only-options.md, docs/cli-reference/quick-reference.md, docs/cli-reference/utility-options.md, docs/deprecations.md, zensical.toml
Documents the new --list-deprecations option and updated deprecation callouts, includes generated docs/deprecations.md, and updates site navigation to include deprecation pages.

Sequence Diagram

sequenceDiagram
  participant User
  participant CLI as arguments.py/__main__.py
  participant Registry as deprecations.py
  participant Docs as scripts/build_deprecation_docs.py

  User->>CLI: run --list-deprecations [format]
  CLI->>Registry: render_deprecations(format)
  Registry-->>CLI: formatted output
  CLI-->>User: print output and exit
  Docs->>Registry: render_release_note_deprecations(version)
  Registry-->>Docs: release-note snippets
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

breaking-change-analyzed

Poem

🐰 A registry of warnings hops into view,
CLI now lists what's slated to retire soon.
Scattered warns gathered, neat and bright,
Docs and tests sing the registry's light.
hop hop 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add deprecation registry and docs' accurately and concisely summarizes the main changes across the pull request, which introduce a centralized deprecation registry and comprehensive documentation for deprecations.
Docstring Coverage ✅ Passed Docstring coverage is 97.37% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch deprecation-registry-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq

codspeed-hq Bot commented May 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 11 untouched benchmarks
⏩ 98 skipped benchmarks1


Comparing deprecation-registry-docs (50b92ff) with main (21118b2)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread src/datamodel_code_generator/__main__.py Fixed
Comment thread src/datamodel_code_generator/__main__.py Fixed
@github-actions

github-actions Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-3188.datamodel-code-generator.pages.dev

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (21118b2) to head (50b92ff).

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #3188    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           93        96     +3     
  Lines        20197     20365   +168     
  Branches      2364      2376    +12     
==========================================
+ Hits         20197     20365   +168     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koxudaxi koxudaxi marked this pull request as ready for review May 25, 2026 04:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
scripts/build_deprecation_docs.py (1)

33-39: ⚡ Quick win

Normalize content before check/write to avoid false mismatches.

Line 33 currently compares raw text, so newline-only differences can fail --check. Normalize both sides (e.g., rstrip() + "\n") before comparing/writing, similar to the approach in scripts/build_cli_docs.py.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/build_deprecation_docs.py` around lines 33 - 39, Normalize the
content read from DOCS_PATH and the generated content before comparing and
before writing to disk to avoid newline-only mismatches: when checking existence
and equality use something like normalized_existing =
DOCS_PATH.read_text(encoding="utf-8").rstrip() + "\n" and normalized_new =
content.rstrip() + "\n" (same approach as scripts/build_cli_docs.py), compare
those normalized strings for the if-check, and when writing call
DOCS_PATH.write_text(normalized_new, encoding="utf-8") so the check and write
use the same canonical form; keep using DOCS_PATH, content, read_text(), and
write_text() from the diff.
tests/main/test_main_general.py (1)

123-130: ⚡ Quick win

Parse --list-deprecations json output before asserting content.

Line 129 currently checks a raw substring only. Parsing first catches malformed/non-JSON output regressions.

✅ Proposed test hardening
+import json
 ...
 def test_list_deprecations_json(capsys: pytest.CaptureFixture[str]) -> None:
     """List registered deprecations as JSON."""
     run_main_with_args(["--list-deprecations", "json"])
     captured = capsys.readouterr()
 
-    assert '"id": "cli.parent-scoped-naming"' in captured.out
+    payload = json.loads(captured.out)
+    assert "cli.parent-scoped-naming" in json.dumps(payload)
     assert not captured.err
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/main/test_main_general.py` around lines 123 - 130, The
test_list_deprecations_json should parse the program output as JSON before
asserting contents: after calling run_main_with_args(...) and capturing via
capsys, call json.loads on captured.out (importing json at top if needed) to
ensure valid JSON, then assert the presence of the deprecation id (e.g. check
any(item.get("id") == "cli.parent-scoped-naming" for item in parsed) or access
the expected key in the parsed dict/list) and still assert not captured.err;
this will make the test fail on malformed/non-JSON output rather than silently
passing on substring matches.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/cli-reference/openapi-only-options.md`:
- Line 1726: The deprecation note for the `--validation` CLI option is missing
the migration hint; update the sentence that currently reads "**Deprecated:**
The `--validation` option is deprecated and will be removed in a future
release." to append a replacement path so it becomes self-contained (e.g., add
"Use `--field-constraints` instead"), ensuring the detailed section includes the
actionable guidance about migrating from `--validation` to
`--field-constraints`.

In `@docs/cli-reference/utility-options.md`:
- Around line 117-121: Replace the fenced triple-backtick code block in the "new
usage" block with an indented code block to satisfy markdownlint MD046: remove
the ```bash fences and indent each command line (e.g., "datamodel-codegen
--list-deprecations", "datamodel-codegen --list-deprecations json",
"datamodel-codegen --list-deprecations markdown") with four spaces so the
commands remain shown but use the indented style expected by the docs linter.

---

Nitpick comments:
In `@scripts/build_deprecation_docs.py`:
- Around line 33-39: Normalize the content read from DOCS_PATH and the generated
content before comparing and before writing to disk to avoid newline-only
mismatches: when checking existence and equality use something like
normalized_existing = DOCS_PATH.read_text(encoding="utf-8").rstrip() + "\n" and
normalized_new = content.rstrip() + "\n" (same approach as
scripts/build_cli_docs.py), compare those normalized strings for the if-check,
and when writing call DOCS_PATH.write_text(normalized_new, encoding="utf-8") so
the check and write use the same canonical form; keep using DOCS_PATH, content,
read_text(), and write_text() from the diff.

In `@tests/main/test_main_general.py`:
- Around line 123-130: The test_list_deprecations_json should parse the program
output as JSON before asserting contents: after calling run_main_with_args(...)
and capturing via capsys, call json.loads on captured.out (importing json at top
if needed) to ensure valid JSON, then assert the presence of the deprecation id
(e.g. check any(item.get("id") == "cli.parent-scoped-naming" for item in parsed)
or access the expected key in the parsed dict/list) and still assert not
captured.err; this will make the test fail on malformed/non-JSON output rather
than silently passing on substring matches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d5408a22-784e-403a-a29d-e0ce74bda783

📥 Commits

Reviewing files that changed from the base of the PR and between 21118b2 and 068a3e8.

⛔ Files ignored due to path filters (9)
  • docs/llms-full.txt is excluded by none and included by none
  • docs/llms.txt is excluded by none and included by none
  • tests/data/expected/main/help/color.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/help/no_color.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/basic.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_list_options.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_options.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_question.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/help_shows_new_options.txt is excluded by !tests/data/**/*.txt and included by none
📒 Files selected for processing (23)
  • docs/cli-reference/index.md
  • docs/cli-reference/manual/list-deprecations.md
  • docs/cli-reference/model-customization.md
  • docs/cli-reference/openapi-only-options.md
  • docs/cli-reference/quick-reference.md
  • docs/cli-reference/utility-options.md
  • docs/deprecations.md
  • pyproject.toml
  • scripts/build_cli_docs.py
  • scripts/build_deprecation_docs.py
  • src/datamodel_code_generator/__main__.py
  • src/datamodel_code_generator/arguments.py
  • src/datamodel_code_generator/cli_options.py
  • src/datamodel_code_generator/deprecations.py
  • src/datamodel_code_generator/format.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • src/datamodel_code_generator/parser/openapi.py
  • src/datamodel_code_generator/util.py
  • tests/main/test_main_general.py
  • tests/test_build_deprecation_docs_script.py
  • tests/test_deprecations.py
  • tox.ini
  • zensical.toml

Comment thread docs/cli-reference/openapi-only-options.md Outdated
Comment thread docs/cli-reference/utility-options.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/datamodel_code_generator/deprecations.py (1)

245-253: ⚡ Quick win

Consider escaping pipe characters in markdown table cells.

The table generation directly interpolates values that could theoretically contain pipe characters |, which would break the markdown table structure. While the current data doesn't contain pipes, adding escaping would prevent future issues.

🛡️ Proposed defensive escaping
+def _escape_markdown_pipe(text: str) -> str:
+    """Escape pipe characters for markdown table cells."""
+    return text.replace("|", "\\|")
+
 def render_deprecations_markdown(*, include_header: bool = True) -> str:
     """Render all deprecations as Markdown."""
     lines: list[str] = []
     # ... existing code ...
     for deprecation in iter_deprecations():
-        replacement = deprecation.replacement or "-"
+        replacement = _escape_markdown_pipe(deprecation.replacement) if deprecation.replacement else "-"
         lines.append(
             f"| `{deprecation.id}` | {deprecation.kind} | `{deprecation.target}` | "
             f"{deprecation.warning_since} | {_format_removal_version(deprecation)} | {replacement} |"
         )

Note: Values wrapped in backticks (like deprecation.id and deprecation.target) are already safe from pipe interpretation in most markdown renderers, so only the unwrapped replacement field needs escaping.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/datamodel_code_generator/deprecations.py` around lines 245 - 253, The
markdown table generation in iter_deprecations() concatenates fields (notably
deprecation.replacement and other unwrapped fields like
deprecation.warning_since/_format_removal_version(...)) without escaping pipe
characters, which can break the table; update the logic before lines.append in
the loop to escape any '|' characters (e.g., replace '|' with '\|' or otherwise
sanitize) for unwrapped cells (replacement, warning_since, removal text) while
leaving backticked fields (deprecation.id, deprecation.target) unchanged, so the
table remains valid even if future data contains pipes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/datamodel_code_generator/deprecations.py`:
- Around line 245-253: The markdown table generation in iter_deprecations()
concatenates fields (notably deprecation.replacement and other unwrapped fields
like deprecation.warning_since/_format_removal_version(...)) without escaping
pipe characters, which can break the table; update the logic before lines.append
in the loop to escape any '|' characters (e.g., replace '|' with '\|' or
otherwise sanitize) for unwrapped cells (replacement, warning_since, removal
text) while leaving backticked fields (deprecation.id, deprecation.target)
unchanged, so the table remains valid even if future data contains pipes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 93633ede-63ad-4fd6-9f85-b7f42dd48116

📥 Commits

Reviewing files that changed from the base of the PR and between fe8b8ca and 303768c.

⛔ Files ignored due to path filters (5)
  • tests/data/expected/main_kr/generate_prompt/basic.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_list_options.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_options.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_question.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/help_shows_new_options.txt is excluded by !tests/data/**/*.txt and included by none
📒 Files selected for processing (1)
  • src/datamodel_code_generator/deprecations.py

@koxudaxi koxudaxi merged commit 0e3d153 into main May 25, 2026
45 checks passed
@koxudaxi koxudaxi deleted the deprecation-registry-docs branch May 25, 2026 07:37
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is a refactoring of deprecation warnings into a central registry with no breaking changes. It adds a new deprecations.py module and --list-deprecations CLI option (both purely additive). Existing deprecation warnings are re-routed through the new registry with the same warning categories and equivalent messages. No generated code output changes, no CLI options or Python API removed, no default behavior changes, no template updates required, and no Python version changes.


This analysis was performed by Claude Code Action

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.59.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants