Skip to content

Commit

Permalink
Add proper marshalling of overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbx9da4 committed Jul 1, 2024
1 parent 4d0e871 commit 5d8e0e0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions workflow/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ type Overlay struct {
Document *Document `yaml:"document,omitempty"`
}

func (o *Overlay) UnmarshalYAML(unmarshal func(interface{}) error) error {
var doc Document
if err := unmarshal(&doc); err == nil {
o.Document = &doc
return nil
}

var fallback FallbackCodeSamples
if err := unmarshal(&fallback); err == nil {
o.FallbackCodeSamples = &fallback
return nil
}

return fmt.Errorf("failed to unmarshal Overlay")
}

func (o Overlay) MarshalYAML() (interface{}, error) {
if o.Document != nil {
return o.Document, nil
}

if o.FallbackCodeSamples != nil {
return o.FallbackCodeSamples, nil
}

return nil, fmt.Errorf("failed to marshal Overlay")
}

type FallbackCodeSamples struct {
FallbackCodeSamplesLanguage string `yaml:"fallbackCodeSamplesLanguage,omitempty"`
}
Expand Down

0 comments on commit 5d8e0e0

Please sign in to comment.