-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] YAML merge operator not supported in custom maps #1038
Comments
Snakeyaml supports anchors and aliases, but it looks like the merge operator was initially supported in the original snakeyaml but was explicitly excluded from the new version snakeyaml-engine that planetiler uses. See: |
Given the large potential benefit of the merge operator, could you consider using another YAML parser that would support it? For reference, the operator is supported by OpenMapTiles and docker compose. |
I don't think I want to move away from snakeyaml since that is the most robust parser for java out there. One option could be to do a post-processing step, since a yaml document like this: source: &label
a: 1
dest:
<<: *label
b: 2 gets parsed by snake-yaml into this json: {"source": {"a": 1}, "dest": {"<<": {"a": 1}, "b": 2}} I could have the yaml parser traverse that struct and hoist any "<<" keys to the parent? That seems like it would match the behavior of pyyaml which hosts the child even if it's not a ref. |
That makes sense! Although not explicitly mentiond the the yaml merge document, I believe the source: &label
a: 1
dest:
c: 3
<<: *label
b: 2 |
Sounds good although with this approach it won't be able to tell whether the merge operator was first or later so either would work. Made a rough POC, check out the test cases here: https://github.com/onthegomap/planetiler/pull/1040/files#diff-fd5539f08265c29356d135323e4f5276e244faf9c16574e159da245abcc642d4 |
Describe the bug
The
<< :
operator in YAML is used to merge two mappings (key-value pairs) together. [See this description for additional details.]It is a powerful feature that simplifies configuration files by allowing copy-modify operation for YAML mappings.
For example, making identical definitions for
geometry: line
andgeometry: polygon
features in the same layer:instead of
To Reproduce
Steps to reproduce the behavior:
merge-operator.yaml
file in an empty directory:Expected behavior
The custom config file should be accepted and produce the same result as the expanded definition.
Environment (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: