Skip to content

fix(high): keep document order of $ref'd path items and callbacks - #739

Open
pcbeingused33 wants to merge 2 commits into
pb33f:mainfrom
pcbeingused33:fix/composed-path-order
Open

pcbeingused33 wants to merge 2 commits into
pb33f:mainfrom
pcbeingused33:fix/composed-path-order

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #733

Rendering paths and callbacks by source line can reorder keys that share a line or come from a YAML merge. Using line 9999 for new entries can also put them ahead of existing entries in long documents.

Walk the parsed mapping in key order, including extensions and merged expressions. Append new paths and callback expressions in insertion order. Apply the same ordering to standard and inline rendering.

The regression tests cover a flow-style mapping with an extension and 16 referenced paths, a callback with an inherited expression, and appending after a referenced path declared beyond line 9999. The composed bundle test also verifies the original cross-file reference case.

This change was prepared with the help of an AI coding assistant.

Paths and Callback sorted their entries by the line of the value node. For a
$ref'd item that is a line in the referenced file, so bundled and rendered
output moved those entries around. Sort by the line of the key instead.
@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ef96408) to head (fcae4e2).
⚠️ Report is 30 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main      #739     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          316       324      +8     
  Lines        40239     41506   +1267     
===========================================
+ Hits         40239     41506   +1267     
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.

@daveshanley daveshanley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the regression test. I confirmed the bundle now keeps the path order from #733. I found three other cases where rendering changes the order.

Comment thread datamodel/high/v3/paths.go Outdated
for lk := range p.low.PathItems.KeysFromOldest() {
if lk.Value == k {
// the key lives in this document, a $ref'd value may not.
ln = lk.KeyNode.Line

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keys can share a line in JSON or flow-style YAML. With an x-note extension followed by 16 $ref paths on one line, /p08 renders before /p00. Could we walk the parsed mapping in key order, including its extensions?

Comment thread datamodel/high/v3/callback.go Outdated
for lk := range c.low.Expression.KeysFromOldest() {
if lk.Value == k {
// the key lives in this document, a $ref'd value may not.
ln = lk.KeyNode.Line

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A callback expression inherited through << keeps its anchor’s line. If the anchor is above the callback, the inherited expression renders before the explicit one. c.low.RootNode.Content already has them in the expected order.

Comment thread datamodel/high/v3/paths.go Outdated
for lk := range p.low.PathItems.KeysFromOldest() {
if lk.Value == k {
// the key lives in this document, a $ref'd value may not.
ln = lk.KeyNode.Line

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If an existing $ref path is declared after line 9,999, a path added with PathItems.Set renders ahead of it because the new path gets the fallback 9999. Could we append new paths and callback expressions in insertion order after the parsed entries?

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Thanks for finding these cases. Paths and callbacks now follow the parsed mapping order, including extensions and inherited expressions. Entries added with Set follow the parsed entries in insertion order. Regression tests cover all three cases in standard and inline rendering.

This comment was drafted with Claude Code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BundleDocumentComposed moves $ref'd path items ahead of inline ones

2 participants