geofffranks / spruce

A BOSH template merge tool
MIT License
427 stars 77 forks source link

cannot reference path with key containing '.' #298

Closed thomasmitchell closed 2 years ago

thomasmitchell commented 4 years ago
---
stuff:
- name: beep.boop
  properties:
    thing: foo

want: (( grab stuff.beep.boop.properties.thing ))

results in:

1 error(s) detected:  - $.want: Unable to resolve `stuff.beep.boop.properties.thing`: `$.stuff.beep`
   → could not be found in the datastructure

stuff.[beep.boop].properties.thing stuff."beep.boop".properties.thing stuff.beep\.boop.properties.thing these might be valid ways to escape such a path. Do you think that such an implementation would conflict greatly with existing templates?

thomasmitchell commented 4 years ago

It's also possible to attempt combining all combinations of dot-joined key names if a path cannot be found in the datastructure, which would provide a no-user-change-required way of doing this, but I'm not sure if that would have too large of a computation-time impact for such a niche edge-case.

thomasmitchell commented 4 years ago

This extends to hashes as well

---
stuff:
  beep.boop: foo

want: (( grab stuff.beep.boop ))
thomasmitchell commented 4 years ago

Existing workaround is to reference both from a pruned source that can be referenced, like:

---
meta:
  thing: foo
stuff:
  beep.boop: (( grab meta.thing ))

want: (( grab meta.thing ))
geofffranks commented 4 years ago

stuff.[beep.boop].properties.thing is probably the right option. I think this only affects finding objects inside arrays based off a key (name/id/key properties), seems to be achievable via the square-bracket notation with straight up hashes:

https://play.spruce.cf/#813d656ea9417d287dc51c85a6d1178a

geofffranks commented 2 years ago

closing as stale