yaml icon indicating copy to clipboard operation
yaml copied to clipboard

Custom tag support?

Open jeroenvandijk opened this issue 6 years ago • 2 comments

Hi Owain,

Thank you for this project. At the moment I'm using it to generate YAML strings in Cloudformation templates. I would like to use it to read external Cloudformation templates as well. Unfortunately these templates have custom tags [1]. I've tried some hackery to get this working, but no luck so far. Do you have the intention to support custom tags? Or maybe you already have some direction how I could add this functionality?

Thanks, Jeroen

[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html#intrinsic-function-reference-sub-syntax.yaml

jeroenvandijk avatar Oct 03 '18 10:10 jeroenvandijk

Jeroen, I successfully parsed a CF template by using the :constructor keyword param as mentioned in the current README:

(let [template-file (first args)
      template-yaml (yaml/parse-string (slurp template-file) :constructor yaml.reader/passthrough-constructor)]
   (println template-yaml)))

tpot avatar Jul 02 '19 09:07 tpot

@tpot Thanks for the feedback. I think I have tried the passthrough-constructor before. Unfortunately it removes the necessary information (or maybe I'm missing another way to use it):

➜  ~ clj -Sdeps '{:deps {io.forward/yaml {:mvn/version "1.0.9"}}}'
Clojure 1.10.0
user=>  (require '[yaml.core :as yaml])
nil
user=> (yaml/parse-string "Fn::Sub:
  - String
  - { Var1Name: Var1Value, Var2Name: Var2Value }" :constructor yaml.reader/passthrough-constructor)
#ordered/map ([:Fn::Sub ["String" #ordered/map ([:Var1Name "Var1Value"] [:Var2Name "Var2Value"])]])
user=>
(yaml/parse-string "!Sub
  - String
  - { Var1Name: Var1Value, Var2Name: Var2Value }" :constructor yaml.reader/passthrough-constructor)
["String" #ordered/map ([:Var1Name "Var1Value"] [:Var2Name "Var2Value"])]

Ideally the !Sub tag would be added somewhere so this (essential) information isn't lost.

jeroenvandijk avatar Jul 02 '19 10:07 jeroenvandijk