Skip to content

Write, split and decode JSON Pointer tokens in one place - #5580

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
pointer-codec
Oct 29, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
pointer-codec

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Standardized JSON Pointer handling across schema references, paths, and document traversal.
    • Improved consistency when decoding escaped tokens, parsing URI fragments, and recognizing array indices.
    • Invalid percent escapes, UTF-8 sequences, and noncanonical pointer escapes are rejected during reference parsing.
    • Architecture guidance and checks now document and enforce the shared JSON Pointer layer.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T19:32:59.417525Z 079369b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 14d93af and 079369b.

Files ignored due to path filters: 3
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/architecture_boundaries/cli.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/architecture_boundaries/violations.txt is excluded by !tests/data/**/*.txt and included by none
Files selected for processing: 20
  • docs/architecture.md
  • scripts/check_architecture_boundaries.py
  • scripts/check_decision_homes.py
  • scripts/decision_homes.toml
  • src/datamodel_code_generator/_client/pagination.py
  • src/datamodel_code_generator/_fastapi/callbacks.py
  • src/datamodel_code_generator/_fastapi/source_document.py
  • src/datamodel_code_generator/_json_pointer.py
  • src/datamodel_code_generator/_json_schema.py
  • src/datamodel_code_generator/_openapi_generation.py
  • src/datamodel_code_generator/_recommend/_metrics.py
  • src/datamodel_code_generator/_recommend/_signals.py
  • src/datamodel_code_generator/_target_binding.py
  • src/datamodel_code_generator/_target_documents.py
  • src/datamodel_code_generator/parser/_api_reference.py
  • src/datamodel_code_generator/parser/_schema_graph.py
  • src/datamodel_code_generator/parser/asyncapi.py
  • src/datamodel_code_generator/parser/base.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • src/datamodel_code_generator/reference.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The PR adds a shared JSON Pointer codec and updates architecture and decision-home checks to recognize it. Existing parser, reference, client, recommendation, and FastAPI code paths now use shared helpers for token parsing, escaping, fragment handling, and array-index checks.

Changes: Shared JSON Pointer Codec

Layer / File(s) Summary
Codec and architecture rules
src/datamodel_code_generator/_json_pointer.py, scripts/check_architecture_boundaries.py, docs/architecture.md, scripts/check_decision_homes.py, scripts/decision_homes.toml
A shared codec provides token escaping and decoding, pointer joining and parsing, fragment parsing, and array-index validation. Architecture rules classify the codec as a leaf layer. Decision-home scanning adds string-literal matching and excluded places, and its configuration records the codec’s decision home.
Fragment parsing and validation
src/datamodel_code_generator/parser/_api_reference.py, src/datamodel_code_generator/_target_binding.py, src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/_recommend/_metrics.py, src/datamodel_code_generator/_client/pagination.py, src/datamodel_code_generator/_recommend/_signals.py, src/datamodel_code_generator/_openapi_generation.py
These reference and fragment consumers now use shared parsing, validation, and tokenization helpers. API-reference parsing retains its errors for malformed percent encoding, invalid UTF-8, and noncanonical escapes.
Pointer construction and traversal
src/datamodel_code_generator/_fastapi/callbacks.py, src/datamodel_code_generator/_fastapi/source_document.py, src/datamodel_code_generator/_json_schema.py, src/datamodel_code_generator/_target_documents.py, src/datamodel_code_generator/parser/_schema_graph.py, src/datamodel_code_generator/parser/asyncapi.py, src/datamodel_code_generator/parser/jsonschema.py, src/datamodel_code_generator/reference.py
These consumers now use shared helpers to construct or traverse pointers and validate array indices. Local pointer helpers and inline escaping logic are removed.

Priority: Low

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

Change: Refactor

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · up to 07936

No actionable merge-blocking issue is established for the JSON Pointer consolidation. Merge readiness remains subject to normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 72.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: centralizing JSON Pointer token writing, splitting, and decoding.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 72.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 25 functions across 17 files. (3 skipped: 2 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 48.13%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

⚡ 52 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_simple_msgspec_unset_field_rendering 544.3 ms 302.5 ms +79.94%
⚡ test_perf_client_calls[sync] 42.4 ms 24 ms +76.95%
⚡ test_perf_client_calls[async] 46.9 ms 27.2 ms +72.55%
⚡ test_perf_scalar_root_collapsed_builtin 221.3 ms 132 ms +67.69%
⚡ test_perf_load_pyproject_config[mapping-None] 377 µs 227.7 µs +65.58%
⚡ test_perf_load_pyproject_config[config-multiple] 386.4 µs 234.1 µs +65.1%
⚡ test_perf_load_pyproject_config[config-None] 371.8 µs 229.3 µs +62.14%
⚡ test_perf_local_reference_file_resolution 137.8 ms 85.7 ms +60.87%
⚡ test_perf_load_pyproject_config[mapping-multiple] 383.5 µs 238.7 µs +60.66%
⚡ test_perf_false_reference_validation 280.2 ms 177.1 ms +58.18%
⚡ test_perf_large_models_dataclass_builtin 1,460.7 ms 929.3 ms +57.18%
⚡ test_perf_ordinary_array_constraint_generation 2.1 s 1.3 s +56.92%
⚡ test_perf_large_models_msgspec 2.1 s 1.3 s +56.34%
⚡ test_perf_large_models_typed_dict[total-false-requiredness] 1,219.9 ms 781.4 ms +56.11%
⚡ test_perf_large_models_single_module_stdout 1.6 s 1 s +55.27%
⚡ test_perf_large_models_typed_dict[legacy-requiredness] 1,214.3 ms 788 ms +54.09%
⚡ test_perf_unique_items_schema_validators 2.2 s 1.4 s +53.6%
⚡ test_perf_large_models_pydantic_v2_builtin 1,364.9 ms 892.4 ms +52.94%
⚡ test_perf_all_options_enabled 6.4 s 4.2 s +51.87%
⚡ test_perf_recommend_options_full_kubernetes_style 16.9 s 11.2 s +51.76%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing pointer-codec (079369b) with main (14d93af)

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. ↩

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit 3f719a4 into main Oct 29, 2026
164 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the pointer-codec branch October 29, 2026 19:50
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor. It moves RFC 6901 JSON Pointer token escaping, unescaping, joining, splitting, fragment decoding and the array-index check into a new private leaf module, _json_pointer.py. Callers in the parsers, reference.py, the schema graph, the target and client modules, and the recommend helpers now use it. Each replacement gives the same result as the inline code it replaces: escape order, unescape order, empty-fragment and named-anchor handling, the noncanonical percent and tilde checks, and the array-index grammar are all unchanged. The only removed definitions are private helpers: _tokens, _pointer, _decode_json_pointer_part, the _BAD_PERCENT and _BAD_ESCAPE regexes, _JSON_POINTER_ARRAY_INDEX, and escape_pointer_token and pointer_tokens in the private _target_documents module. No public CLI option, Python API, template or supported Python version changes. The rest of the diff touches internal architecture docs, boundary-checker scripts, the decision-homes config and expected test fixtures for those scripts. The behaviour diff gate does list accepted cells, but their notes say they come from allOf handling: an allOf whose parts admit no object now becomes a RootModel or alias instead of an empty object model. This diff contains no allOf or model-kind logic, so those cells come from other changes since the last release, not from this PR.


This analysis was produced by the release draft workflow

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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

1 participant