-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathguidance_catalog_yaml.go
More file actions
57 lines (45 loc) · 1.45 KB
/
guidance_catalog_yaml.go
File metadata and controls
57 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: Apache-2.0
package gemara
import "github.com/gemaraproj/go-gemara/internal/codec"
// UnmarshalYAML allows decoding guidance from older/alternate YAML schemas.
// It supports:
// - `families` -> `groups`
// - `document-type` -> `type`
func (g *GuidanceCatalog) UnmarshalYAML(data []byte) error {
type alias struct {
Title string `yaml:"title"`
Metadata Metadata `yaml:"metadata"`
Extends []ArtifactMapping `yaml:"extends,omitempty"`
Imports []MultiEntryMapping `yaml:"imports,omitempty"`
Type GuidanceType `yaml:"type,omitempty"`
DocumentType GuidanceType `yaml:"document-type,omitempty"`
FrontMatter string `yaml:"front-matter,omitempty"`
Groups []Group `yaml:"groups,omitempty"`
Families []Group `yaml:"families,omitempty"`
Guidelines []Guideline `yaml:"guidelines,omitempty"`
Exemptions []Exemption `yaml:"exemptions,omitempty"`
}
var tmp alias
if err := codec.UnmarshalYAML(data, &tmp); err != nil {
return err
}
g.Title = tmp.Title
g.Metadata = tmp.Metadata
g.Extends = tmp.Extends
g.Imports = tmp.Imports
g.FrontMatter = tmp.FrontMatter
g.Guidelines = tmp.Guidelines
g.Exemptions = tmp.Exemptions
if tmp.Type != 0 {
g.GuidanceType = tmp.Type
} else {
g.GuidanceType = tmp.DocumentType
}
// Prefer `groups` when present, otherwise fall back to `families`.
if len(tmp.Groups) > 0 {
g.Groups = tmp.Groups
} else {
g.Groups = tmp.Families
}
return nil
}