From 7098bd6b1314378a61590df4c20e0b88c7912289 Mon Sep 17 00:00:00 2001 From: Bastian Rihm Date: Fri, 5 Apr 2024 14:34:03 +0200 Subject: [PATCH] Add yaml parser workaround for anchors --- internal/models/models.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/models/models.go b/internal/models/models.go index d1d22d90..94eb37cb 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -12,7 +12,22 @@ import ( // Unmarshal parses the content of models.yml to a datastruct.q func Unmarshal(r io.Reader) (map[string]Model, error) { var m map[string]Model - if err := yaml.NewDecoder(r).Decode(&m); err != nil { + + var tmp map[string]interface{} + if err := yaml.NewDecoder(r).Decode(&tmp); err != nil { + return m, err + } + + if _, ok := tmp["_meta"]; ok { + delete(tmp, "_meta") + } + + cleanYml, err := yaml.Marshal(tmp) + if err != nil { + return m, err + } + + if err := yaml.Unmarshal(cleanYml, &m); err != nil { return nil, fmt.Errorf("decoding models: %w", err) } return m, nil