Repository navigation
Write, split and decode JSON Pointer tokens in one place - #5580
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
|
No actionable comments were generated in the recent review.
|
| 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:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Refactor
Possibly related issues
- Server and client generation read JSON Pointer array indexes and keys by different rules than the parser #5579: The issue identifies inconsistent JSON Pointer index and mapping-key rules across several code paths; this PR centralizes token handling across those paths.
- Server and client generation accept '-1' as a JSON Pointer array index in link, callback and security scheme $refs #5576: The issue concerns inconsistent JSON Pointer array-index handling; this PR adds shared array-index validation and migrates existing consumers.
- Client and server generation read a percent-encoded slash in a $ref differently from the parser #5578: The issue concerns percent-decoding and token splitting for JSON Pointer fragments; this PR adds shared fragment parsing and migrates fragment consumers.
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5513: Both PRs update pointer consumers, including
SourceDocumentandSourceLease.exists. - datamodel-code-generator/datamodel-code-generator#5511: Both PRs address JSON Schema pointer access; this PR migrates JSON Schema code to shared token parsing and array-index helpers.
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: 
4 · 
1
-
Failed checks: 1 inconclusive Passed checks: 4 passedFull 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.
Comment @coderabbitai help to get the list of available commands.
Merging this PR will improve performance by 48.13%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Breaking Change AnalysisResult: 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 |
|
🎉 Released in 0.88.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit