Skip to content

Add schema format guide tables#3529

Merged
koxudaxi merged 3 commits into
mainfrom
docs-schema-format-guides
Jul 2, 2026
Merged

Add schema format guide tables#3529
koxudaxi merged 3 commits into
mainfrom
docs-schema-format-guides

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Documentation

    • Added a new Input Format Guide section to the schema documentation, including tables for supported input formats, schema-version behavior, accepted source shapes, and detailed type-mapping coverage across GraphQL, Avro, Protocol Buffers, XML Schema, and Python input models.
    • Expanded the guide content to align with current code-derived format support details.
  • Tests

    • Added a check to confirm the generated Input Format Guide output matches the expected documentation.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 47f07beb-d3e1-4ab1-8eaa-775297478dbc

📥 Commits

Reviewing files that changed from the base of the PR and between 63f56fb and e6a7cf8.

📒 Files selected for processing (1)
  • scripts/build_schema_docs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/build_schema_docs.py

📝 Walkthrough

Walkthrough

This PR adds an auto-generated "Input Format Guide" section to scripts/build_schema_docs.py, then writes that generated content into two docs pages and validates the output with a new test.

Changes

Input Format Guide Generation

Layer / File(s) Summary
Constants, markers, and metadata
scripts/build_schema_docs.py
Expanded imports, added path constants, new guide markers, and per-input-format label, note, and version-support mappings.
Markdown helpers and route tables
scripts/build_schema_docs.py
Added Markdown rendering helpers, AST utilities, parser-route inference, schema-version labeling, accepted-source-shape generation, and format-coverage aggregation.
Format-specific type guides
scripts/build_schema_docs.py
Added GraphQL, Avro, Protobuf, XML Schema, and Python input-type table generators from parser source and related metadata.
Content assembly, wiring, and tests
scripts/build_schema_docs.py, tests/test_build_schema_docs_script.py, docs/supported_formats.md, docs/supported-data-types.md
Assembles the guide content, wires it into two generated docs targets, adds a test for the generated output, and inserts the generated guide into both documentation files.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: gaborbernat

🚥 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 clearly matches the main change: adding schema format guide tables and related documentation generation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 docs-schema-format-guides

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.

@codspeed-hq

codspeed-hq Bot commented Jul 1, 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 docs-schema-format-guides (e6a7cf8) with main (0f09aee)

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.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread scripts/build_schema_docs.py Fixed
Comment thread scripts/build_schema_docs.py Fixed

@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 (3)
scripts/build_schema_docs.py (3)

394-409: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Validate input_format_order() against the enum.

A future InputFileType addition would be silently omitted from the guide. Add a set check against set(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 win

Fail closed when parser-route introspection stops matching.

If _build_parser() is renamed/refactored or the AST pattern no longer matches, this currently emits JsonSchemaParser routes 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 win

Don’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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f09aee and 63f56fb.

⛔ Files ignored due to path filters (1)
  • tests/data/expected/schema_docs/input_format_guide.txt is excluded by !tests/data/**/*.txt and included by none
📒 Files selected for processing (4)
  • docs/supported-data-types.md
  • docs/supported_formats.md
  • scripts/build_schema_docs.py
  • tests/test_build_schema_docs_script.py

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0f09aee) to head (e6a7cf8).

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     
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 Harness.
📢 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 merged commit b126855 into main Jul 2, 2026
61 checks passed
@koxudaxi koxudaxi deleted the docs-schema-format-guides branch July 2, 2026 02:36
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: 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 (from typing import TYPE_CHECKING) was simply expanded to include Any. None of the breaking-change categories apply.


This analysis was performed by Claude Code Action

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.67.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