Skip to content

Releases: oasdiff/yaml

v0.1.0 — Single Unmarshal API + DisableTimestamps (BREAKING)

12 May 19:26
21c11f3

Choose a tag to compare

⚠ BREAKING CHANGE

This release collapses three unmarshal entry points (Unmarshal, UnmarshalWithOriginTree, UnmarshalWithDecodeOpts) into a single Unmarshal that takes a DecodeOpts struct. It also adds DisableTimestamps to DecodeOpts so callers can opt out of YAML 1.1 implicit-timestamp resolution.

Any external caller of the package needs to update call sites. Migration is mechanical.

Final API

func Unmarshal(y []byte, o interface{}, decode DecodeOpts, opts ...JSONOpt) (*OriginTree, error)

type DecodeOpts struct {
    Origin            OriginOpt // opt into origin tracking
    DisableTimestamps bool      // opt out of YAML 1.1 implicit timestamps
}

type OriginOpt struct {
    Enabled bool
    File    string
}

The *OriginTree return is nil when Origin.Enabled is false. The variadic JSONOpt list still configures the JSON unmarshal step.

Why one entry point

UnmarshalWithDecodeOpts already covered every case Unmarshal and UnmarshalWithOriginTree did, and the only public consumer (getkin/kin-openapi) migrates cleanly in a few sites. Maintaining three near-identical wrappers added godoc surface and naming overhead without ergonomic benefit. Folding to one signature also exposes DisableTimestamps to every caller uniformly, which is the right shape now that real-world OpenAPI specs need it (date-shaped strings as map keys are otherwise silently resolved to time.Time and break string-keyed lookup).

Migration cheatsheet

// Plain decode
- err := yaml.Unmarshal(y, &v)
+ _, err := yaml.Unmarshal(y, &v, yaml.DecodeOpts{})

// Origin tracking
- tree, err := yaml.UnmarshalWithOriginTree(y, &v, yaml.OriginOpt{Enabled: true, File: f})
+ tree, err := yaml.Unmarshal(y, &v, yaml.DecodeOpts{Origin: yaml.OriginOpt{Enabled: true, File: f}})

// New: opt out of YAML 1.1 timestamp resolution
+ _, err := yaml.Unmarshal(y, &v, yaml.DecodeOpts{DisableTimestamps: true})

Dependencies

Bumps the underlying oasdiff/yaml3 to v0.0.13, which adds the Decoder.DisableTimestamps(bool) decoder option this release exposes.

PR

#9

v0.0.7

02 Apr 15:21
ba13ca1

Choose a tag to compare

fix: convert non-string map keys to string in OriginTree (integer HTTP status codes)

v0.0.6

02 Apr 15:17
9c3fc5f

Choose a tag to compare

fix: handle map[interface{}]interface{} in extractOrigins for integer YAML keys (e.g. HTTP status codes)