Skip to content

Commit 7633481

Browse files
reuvenharrisonclaude
authored andcommitted
feat: migrate to oasdiff/yaml v0.1.0 single Unmarshal API + enable DisableTimestamps
Bumps: * github.com/oasdiff/yaml v0.0.9 -> v0.1.0 * github.com/oasdiff/yaml3 v0.0.12 -> v0.0.13 yaml v0.1.0 consolidates three unmarshal entry points (Unmarshal, UnmarshalWithOriginTree, UnmarshalWithDecodeOpts) into a single Unmarshal with the signature: Unmarshal(y []byte, o interface{}, decode DecodeOpts, opts ...JSONOpt) (*OriginTree, error) DecodeOpts carries Origin (tracking) and DisableTimestamps (YAML 1.1 implicit-timestamp resolution opt-out, backed by yaml3 v0.0.13). This PR migrates every yaml.Unmarshal / yaml.UnmarshalWithOriginTree call site (4 production sites + 8 test sites) to the new signature, setting DisableTimestamps: true everywhere. Real-world OpenAPI specs use date-shaped strings as map keys (e.g. revision dates like "1344-08-22") which the YAML 1.1 default resolves to time.Time — that resolution is the root cause of validation errors that surface as misleading time.Time-stringified values in error messages, and in some cases breaks string-keyed lookup entirely. Testdata golden files in openapi3/testdata/apis_guru_openapi_directory/ regenerated by the existing golden helper: * Several previously-failing specs now validate cleanly (golden files removed by the helper's os.Remove path). * Others show updated error messages where date-shaped scalars no longer appear as stringified time.Time. `go test ./...` clean across all packages. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 94286d9 commit 7633481

40 files changed

Lines changed: 4534 additions & 114 deletions

File tree

‎cmd/validate/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func main() {
4848
OpenAPI string `json:"openapi" yaml:"openapi"`
4949
Swagger string `json:"swagger" yaml:"swagger"`
5050
}
51-
if err := yaml.Unmarshal(data, &vd); err != nil {
51+
if _, err := yaml.Unmarshal(data, &vd, yaml.DecodeOpts{DisableTimestamps: true}); err != nil {
5252
log.Fatal(err)
5353
}
5454

@@ -98,7 +98,7 @@ func main() {
9898
}
9999

100100
var doc openapi2.T
101-
if err := yaml.Unmarshal(data, &doc); err != nil {
101+
if _, err := yaml.Unmarshal(data, &doc, yaml.DecodeOpts{DisableTimestamps: true}); err != nil {
102102
log.Fatalln("Loading error:", err)
103103
}
104104

‎go.mod‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require (
66
github.com/go-openapi/jsonpointer v0.21.0
77
github.com/gorilla/mux v1.8.0
88
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
9-
github.com/oasdiff/yaml v0.0.9
10-
github.com/oasdiff/yaml3 v0.0.12
9+
github.com/oasdiff/yaml v0.1.0
10+
github.com/oasdiff/yaml3 v0.0.13
1111
github.com/perimeterx/marshmallow v1.1.5
1212
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
1313
github.com/stretchr/testify v1.9.0

‎go.sum‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
2020
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
2121
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
2222
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
23-
github.com/oasdiff/yaml v0.0.9 h1:zQOvd2UKoozsSsAknnWoDJlSK4lC0mpmjfDsfqNwX48=
24-
github.com/oasdiff/yaml v0.0.9/go.mod h1:8lvhgJG4xiKPj3HN5lDow4jZHPlx1i7dIwzkdAo6oAM=
25-
github.com/oasdiff/yaml3 v0.0.12 h1:75urAtPeDg2/iDEWwzNrLOWxI9N/dCh81nTTJtokt2M=
26-
github.com/oasdiff/yaml3 v0.0.12/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
23+
github.com/oasdiff/yaml v0.1.0 h1:0bqZjfKc/8S9urj4JuwepX41WX9EoA6ifhU3SV06cXg=
24+
github.com/oasdiff/yaml v0.1.0/go.mod h1:kOlRmMdL2X3vucLCEQO5u61SU22RysnfXvcttrZA1O0=
25+
github.com/oasdiff/yaml3 v0.0.13 h1:06svmvOHOVBqF81+sY2EUScvUI/iS/vl2VIeUUxZQwg=
26+
github.com/oasdiff/yaml3 v0.0.13/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
2727
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
2828
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
2929
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

‎openapi2/marsh.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func unmarshal(data []byte, v any) error {
2525
}
2626

2727
// UnmarshalStrict(data, v) TODO: investigate how ymlv3 handles duplicate map keys
28-
if yamlErr = yaml.Unmarshal(data, v); yamlErr == nil {
28+
if _, yamlErr = yaml.Unmarshal(data, v, yaml.DecodeOpts{DisableTimestamps: true}); yamlErr == nil {
2929
return nil
3030
}
3131

‎openapi2/openapi2_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Example() {
4242
panic(err)
4343
}
4444
var docAgainFromYAML openapi2.T
45-
if err = yaml.Unmarshal(outputYAML, &docAgainFromYAML); err != nil {
45+
if _, err = yaml.Unmarshal(outputYAML, &docAgainFromYAML, yaml.DecodeOpts{DisableTimestamps: true}); err != nil {
4646
panic(err)
4747
}
4848
if !reflect.DeepEqual(doc, docAgainFromYAML) {

‎openapi2/v2_apis_guru_openapi_directory_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestV2ApisGuruOpenapiDirectory(t *testing.T) {
156156
require.NoError(t, err)
157157

158158
var doc openapi2.T
159-
err = yaml.Unmarshal(data, &doc)
159+
_, err = yaml.Unmarshal(data, &doc, yaml.DecodeOpts{DisableTimestamps: true})
160160
golden(t, err, shortName, "load")
161161
})
162162
}

‎openapi2conv/issue1062_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ components:
5959
`
6060

6161
var doc3 openapi3.T
62-
err := yaml.Unmarshal([]byte(v3Spec), &doc3)
62+
_, err := yaml.Unmarshal([]byte(v3Spec), &doc3, yaml.DecodeOpts{DisableTimestamps: true})
6363
require.NoError(t, err, "unmarshal v3 spec")
6464

6565
// Pre-fix: this call panicked with

‎openapi2conv/issue1069_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ paths:
199199
for _, tt := range tests {
200200
t.Run(tt.name, func(t *testing.T) {
201201
var doc3 openapi3.T
202-
err := yaml.Unmarshal([]byte(tt.v3Spec), &doc3)
202+
_, err := yaml.Unmarshal([]byte(tt.v3Spec), &doc3, yaml.DecodeOpts{DisableTimestamps: true})
203203
require.NoError(t, err)
204204

205205
v2, err := openapi2conv.FromV3(&doc3)

‎openapi2conv/issue187_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func v2v3JSON(spec2 []byte) (doc3 *openapi3.T, err error) {
2323

2424
func v2v3YAML(spec2 []byte) (doc3 *openapi3.T, err error) {
2525
var doc2 openapi2.T
26-
if err = yaml.Unmarshal(spec2, &doc2); err != nil {
26+
if _, err = yaml.Unmarshal(spec2, &doc2, yaml.DecodeOpts{DisableTimestamps: true}); err != nil {
2727
return
2828
}
2929
doc3, err = openapi2conv.ToV3(&doc2)

‎openapi3/issue883_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ paths:
5757
require.YAMLEq(t, spec, string(marshalledYaml))
5858

5959
var newDoc openapi3.T
60-
err = yaml.Unmarshal(marshalledYaml, &newDoc)
60+
_, err = yaml.Unmarshal(marshalledYaml, &newDoc, yaml.DecodeOpts{DisableTimestamps: true})
6161
require.NoError(t, err)
6262
require.NotNil(t, newDoc.Paths)
6363
require.Equal(t, doc, &newDoc)

0 commit comments

Comments
 (0)