Skip to content

Commit a70c470

Browse files
committed
Switch to sigs.k8s.io/yaml instead of default; fixup jozufile struct
Switch to using sigs.k8s.io/yaml for YAML serialization/deserialization to avoid ambiguity between JSON and YAML representations of the Jozufile. gopkg.in/yaml.v3 uses a separate struct tag for YAML fields, leaving ambiguity between the JSON and YAML serialized format of a struct, unless struct tags are repeated: type myStruct struct { myfield string `json:"myfield,omitempty",yaml:"myfield,omitempty"` } sigs.k8s.io/yaml instead reuses json struct tags, allowing for one specification to apply to both formats. In addition, this commit adds the `omitempty` tag to fields, to avoid serializing empty structs, and converts struct fields to pointers to ensure they can be nil/empty
1 parent daec660 commit a70c470

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require (
66
github.com/opencontainers/go-digest v1.0.0
77
github.com/opencontainers/image-spec v1.1.0-rc5
88
github.com/spf13/cobra v1.8.0
9-
gopkg.in/yaml.v3 v3.0.1
109
oras.land/oras-go/v2 v2.3.1
10+
sigs.k8s.io/yaml v1.4.0
1111
)
1212

1313
require (
@@ -30,6 +30,7 @@ require (
3030
golang.org/x/sys v0.15.0 // indirect
3131
golang.org/x/text v0.14.0 // indirect
3232
gopkg.in/ini.v1 v1.67.0 // indirect
33+
gopkg.in/yaml.v3 v3.0.1 // indirect
3334
)
3435

3536
require (

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8181
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8282
oras.land/oras-go/v2 v2.3.1 h1:lUC6q8RkeRReANEERLfH86iwGn55lbSWP20egdFHVec=
8383
oras.land/oras-go/v2 v2.3.1/go.mod h1:5AQXVEu1X/FKp1F9DMOb5ZItZBOa0y5dha0yCm4NR9c=
84+
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
85+
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

pkg/artifact/jozu_file.go

+31-30
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,59 @@ import (
55
"io"
66
"os"
77

8-
"gopkg.in/yaml.v3"
8+
"sigs.k8s.io/yaml"
99
)
1010

1111
type (
1212
JozuFile struct {
13-
ManifestVersion string `yaml:"manifestVersion"`
14-
Package Package `yaml:"package"`
15-
Code []Code `yaml:"code"`
16-
DataSets []DataSet `yaml:"datasets"`
17-
Models []TrainedModel `yaml:"models"`
13+
ManifestVersion string `json:"manifestVersion"`
14+
Package Package `json:"package,omitempty"`
15+
Code []Code `json:"code,omitempty"`
16+
DataSets []DataSet `json:"datasets,omitempty"`
17+
Models []TrainedModel `json:"models,omitempty"`
1818
}
1919

2020
Package struct {
21-
Name string `yaml:"name"`
22-
Version string `yaml:"version"`
23-
Description string `yaml:"description"`
24-
Authors []string `yaml:"authors"`
21+
Name string `json:"name,omitempty"`
22+
Version string `json:"version,omitempty"`
23+
Description string `json:"description,omitempty"`
24+
License string `json:"license,omitempty"`
25+
Authors []string `json:"authors,omitempty"`
2526
}
2627

2728
Code struct {
28-
Path string `yaml:"path"`
29-
License string `yaml:"license"`
30-
Description string `yaml:"description"`
29+
Path string `json:"path,omitempty"`
30+
License string `json:"license,omitempty"`
31+
Description string `json:"description,omitempty"`
3132
}
3233

3334
DataSet struct {
34-
Name string `yaml:"name"`
35-
Path string `yaml:"path"`
36-
Description string `yaml:"description"`
37-
License string `yaml:"license"`
38-
Preprocessing string `yaml:"preprocessing"`
35+
Name string `json:"name,omitempty"`
36+
Path string `json:"path,omitempty"`
37+
Description string `json:"description,omitempty"`
38+
License string `json:"license,omitempty"`
39+
Preprocessing string `json:"preprocessing,omitempty"`
3940
}
4041

4142
TrainedModel struct {
42-
Name string `yaml:"name"`
43-
Path string `yaml:"path"`
44-
Framework string `yaml:"framework"`
45-
Version string `yaml:"version"`
46-
Description string `yaml:"description"`
47-
License string `yaml:"license"`
48-
Training Training `yaml:"training"`
49-
Validation Validation `yaml:"validation"`
43+
Name string `json:"name,omitempty"`
44+
Path string `json:"path,omitempty"`
45+
Framework string `json:"framework,omitempty"`
46+
Version string `json:"version,omitempty"`
47+
Description string `json:"description,omitempty"`
48+
License string `json:"license,omitempty"`
49+
Training *Training `json:"training,omitempty"`
50+
Validation *Validation `json:"validation,omitempty"`
5051
}
5152

5253
Training struct {
53-
DataSet string `yaml:"dataset"`
54-
Parameters map[string]interface{} `yaml:"parameters"`
54+
DataSet string `json:"dataset,omitempty"`
55+
Parameters map[string]interface{} `json:"parameters,omitempty"`
5556
}
5657

5758
Validation struct {
58-
DataSet string `yaml:"dataset"`
59-
Metrics map[string]interface{} `yaml:"metrics"`
59+
DataSet string `json:"dataset,omitempty"`
60+
Metrics map[string]interface{} `json:"metrics,omitempty"`
6061
}
6162
)
6263

0 commit comments

Comments
 (0)