Add schema format guide tables#3529
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds an auto-generated "Input Format Guide" section to ChangesInput Format Guide Generation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Merging this PR will not alter performance
|
|
📚 Docs Preview: https://pr-3529.datamodel-code-generator.pages.dev |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
scripts/build_schema_docs.py (3)
394-409: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winValidate
input_format_order()against the enum.A future
InputFileTypeaddition would be silently omitted from the guide. Add a set check againstset(InputFileType) - {InputFileType.Auto}so docs generation fails when the enum contract changes.🤖 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_schema_docs.py` around lines 394 - 409, The input format ordering in input_format_order() is hardcoded and can silently miss new InputFileType values. Update input_format_order() to validate the returned tuple against the InputFileType enum by checking set(InputFileType) - {InputFileType.Auto} and failing docs generation if any enum members are not included. Keep the existing docs-friendly ordering, but add the completeness check alongside input_format_order() so future enum additions are caught automatically.
357-380: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winFail closed when parser-route introspection stops matching.
If
_build_parser()is renamed/refactored or the AST pattern no longer matches, this currently emitsJsonSchemaParserroutes for every non-overridden input. Raise instead of generating plausible-but-wrong docs.Suggested guard
def parser_routes_from_source() -> dict[InputFileType, str]: """Read _build_parser() and infer InputFileType to parser routes.""" tree = ast.parse(INIT_PATH.read_text(encoding="utf-8")) direct_routes: dict[InputFileType, str] = {} default_route = "JsonSchemaParser" + found_build_parser = False for node in ast.walk(tree): if not isinstance(node, ast.FunctionDef) or node.name != "_build_parser": continue + found_build_parser = True for child in ast.walk(node): if not isinstance(child, ast.Match): continue @@ direct_routes[InputFileType[input_type_name]] = parser_name + if not found_build_parser or not direct_routes: + raise RuntimeError("Could not infer parser routes from _build_parser()") + return {🤖 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_schema_docs.py` around lines 357 - 380, The parser route introspection in parser_routes_from_source() should fail closed instead of defaulting to JsonSchemaParser when _build_parser() cannot be matched. Update parser_routes_from_source() to detect when no matching ast.FunctionDef/_build_parser or no usable ast.Match cases are found, and raise an error rather than returning inferred routes. Keep PARSER_ROUTE_OVERRIDES and direct_routes handling, but only build the final map after confirming the introspection successfully found real parser routes.
693-705: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winDon’t hide Python input-type extraction failures.
Returning
[]leaves a valid-looking table with only the “Multiple--input-model” row. Raise when the source text no longer matches so stale docs are caught.Suggested change
def python_input_type_rows() -> list[tuple[str, str]]: """Return Python input type guide rows from the input model error text.""" input_model_source = (SRC / "datamodel_code_generator" / "input_model.py").read_text(encoding="utf-8") if match := re.search(r"Supported: (?P<types>[^\"']+)", input_model_source): return [(code_label(name), PYTHON_INPUT_TYPE_NOTES.get(name, "-")) for name in match.group("types").split(", ")] - return [] + raise RuntimeError("Could not extract supported Python input model types")🤖 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_schema_docs.py` around lines 693 - 705, The Python input type extraction in python_input_type_rows() is silently falling back to an empty list when the source text no longer matches, which hides stale docs. Update python_input_type_rows() to fail fast instead of returning [] when the re.search for the Supported types text does not match, so generate_python_input_type_table() cannot emit a misleading table; keep the existing code path that builds rows from input_model.py and the markdown_table output unchanged otherwise.
🤖 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 `@scripts/build_schema_docs.py`:
- Around line 394-409: The input format ordering in input_format_order() is
hardcoded and can silently miss new InputFileType values. Update
input_format_order() to validate the returned tuple against the InputFileType
enum by checking set(InputFileType) - {InputFileType.Auto} and failing docs
generation if any enum members are not included. Keep the existing docs-friendly
ordering, but add the completeness check alongside input_format_order() so
future enum additions are caught automatically.
- Around line 357-380: The parser route introspection in
parser_routes_from_source() should fail closed instead of defaulting to
JsonSchemaParser when _build_parser() cannot be matched. Update
parser_routes_from_source() to detect when no matching
ast.FunctionDef/_build_parser or no usable ast.Match cases are found, and raise
an error rather than returning inferred routes. Keep PARSER_ROUTE_OVERRIDES and
direct_routes handling, but only build the final map after confirming the
introspection successfully found real parser routes.
- Around line 693-705: The Python input type extraction in
python_input_type_rows() is silently falling back to an empty list when the
source text no longer matches, which hides stale docs. Update
python_input_type_rows() to fail fast instead of returning [] when the re.search
for the Supported types text does not match, so
generate_python_input_type_table() cannot emit a misleading table; keep the
existing code path that builds rows from input_model.py and the markdown_table
output unchanged otherwise.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7455370d-a24d-444a-8119-088e610f29ba
⛔ Files ignored due to path filters (1)
tests/data/expected/schema_docs/input_format_guide.txtis excluded by!tests/data/**/*.txtand included by none
📒 Files selected for processing (4)
docs/supported-data-types.mddocs/supported_formats.mdscripts/build_schema_docs.pytests/test_build_schema_docs_script.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3529 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 158 158
Lines 34254 34256 +2
Branches 4001 4001
=========================================
+ Hits 34254 34256 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Breaking Change AnalysisResult: No breaking changes detected Reasoning: PR #3529 is a documentation-only change. It modifies docs/supported-data-types.md and docs/supported_formats.md (adding an auto-generated "Input Format Guide" section), the internal docs build script scripts/build_schema_docs.py (adding new table-generation functions), and the associated test file and expected fixture. No changes affect generated code output, CLI options, the Python API, default values/behavior, error handling, Jinja2 templates, or supported Python versions. The only removed line ( This analysis was performed by Claude Code Action |
|
🎉 Released in 0.67.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit
Documentation
Tests