Skip to content

fix: std.parseYaml supports YAML merge keys (<<)#1027

Open
He-Pin wants to merge 4 commits into
databricks:masterfrom
He-Pin:fix/parseyaml-merge-keys
Open

fix: std.parseYaml supports YAML merge keys (<<)#1027
He-Pin wants to merge 4 commits into
databricks:masterfrom
He-Pin:fix/parseyaml-merge-keys

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

fix: std.parseYaml supports YAML merge keys (<<)

Motivation

std.parseYaml did not support YAML merge key expansion. The << key was kept as a literal string key instead of merging the referenced mapping's fields into the parent. Both go-jsonnet and jrsonnet correctly implement this YAML spec feature.

Example:

defaults: &def
  x: 1
  y: 2
item:
  <<: *def
  z: 3

Expected: {"defaults":{"x":1,"y":2},"item":{"x":1,"y":2,"z":3}}
Before: {"defaults":{"x":1,"y":2},"item":{"<<":{"x":1,"y":2},"z":3}}

Modification

  • Platform.scala (JVM): Modified the MappingNode handler in yamlNodeToJson to detect Tag.MERGE on key nodes and inline the referenced mapping's entries with lower priority than explicit keys (per YAML spec). Supports both single alias (<<: *def) and sequence of aliases (<<: [*a, *b]).
  • Test skipped on JS/WASM/Native (different YAML parser — scala-yaml).
  • Added regression test: parseyaml_merge_keys.jsonnet

Result

Merge keys are now correctly expanded, matching go-jsonnet and jrsonnet output.

Implementation Behavior
go-jsonnet Merge keys expanded ✅
jrsonnet Merge keys expanded ✅
C++ jsonnet Anchors not supported (N/A)
sjsonnet (before) << as literal key ❌
sjsonnet (after) Merge keys expanded ✅

The MappingNode handler in Platform.scala now checks for Tag.MERGE on
key nodes. When a merge key is encountered, the referenced mapping (or
sequence of mappings) is resolved and its entries are inlined into the
current mapping with lower priority than explicit keys, matching the
YAML merge key spec and go-jsonnet/jrsonnet behavior.
@He-Pin He-Pin marked this pull request as draft June 24, 2026 12:56
He-Pin added 3 commits June 24, 2026 20:58
Motivation:
The YAML merge key (<<) fix is JVM-only (SnakeYAML specific). The
JS/WASM and Native platforms use scala-yaml which handles merge keys
differently. Skip the test on non-JVM platforms to avoid CI failures.

Modification:
- src-js/FileTests.scala: Add parseyaml_merge_keys.jsonnet to
  skippedTests
- src-jvm-native/FileTests.scala: Add to Scala Native skip list
Motivation:
The skippedTests/testDataSkippedTests filter was only applied to
test_suite, not to new_test_suite. This caused JVM-only tests
(parseyaml_merge_keys.jsonnet) to run and fail on JS/WASM/Native.

Modification:
- src-js/FileTests.scala: Add .filter(f => !skippedTests.contains(f))
  to new_test_suite section
- src-jvm-native/FileTests.scala: Add .filter(f =>
  !testDataSkippedTests.contains(f.last)) to new_test_suite section
@He-Pin He-Pin marked this pull request as ready for review June 24, 2026 14:01
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.

1 participant