Skip to content

chore: migrate from gopkg.in/yaml.v3 to go.yaml.in/yaml/v3 - #269

Merged
TristanSpeakEasy merged 15 commits into
speakeasy-api:mainfrom
AdamMagued:feat-issue-201-yaml-v3-migration
Oct 16, 2026
Merged

TristanSpeakEasy merged 15 commits into
speakeasy-api:mainfrom
AdamMagued:feat-issue-201-yaml-v3-migration

Conversation

@AdamMagued

@AdamMagued AdamMagued commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Migrates imports and go.mod module dependencies from legacy gopkg.in/yaml.v3 to maintained go.yaml.in/yaml/v3 (v3.0.5).

Resolves #201.

Summary of changes:

  • Promoted direct module dependency on go.yaml.in/yaml/v3 v3.0.5 across go.mod manifests.
  • Migrated package imports across the codebase from gopkg.in/yaml.v3 to go.yaml.in/yaml/v3.
  • Bridged external query evaluators (jsonpath, yamlpath) in overlay with zero-copy node casting to maintain compatibility without performance degradation.
  • All unit tests and go vet checks pass cleanly.

Summary by cubic

Migrates the YAML library from the unmaintained gopkg.in/yaml.v3 to the maintained go.yaml.in/yaml/v3 fork, resolving #201.

  • Updates all YAML imports and go.mod dependencies across the codebase, including cmd/openapi, openapi/linter/customrules, and jsonschema/oas3/tests, and aligns their root-module pseudo-versions.
  • Bumps github.com/speakeasy-api/jsonpath to v0.7.0 and switches the jsonpath and yamlpath evaluators to go.yaml.in/yaml/v3, dropping the bridge code that converted nodes between the two modules.
  • Encodes typed-nil legacy yaml nodes as null in sequencedmap.

Written for commit f308ebf. Summary will update on new commits.

View guided diff

@AdamMagued
AdamMagued requested a review from a team as a code owner October 11, 2026 15:14

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 176 files

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Re-trigger cubic

Comment thread jsonpointer/jsonpointer.go
Comment thread hashing/hashing.go
Comment thread values/value.go
Comment thread validation/fix.go
Comment thread sequencedmap/map.go
Comment thread overlay/jsonpath.go Outdated

@TristanSpeakEasy TristanSpeakEasy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution Adam, good to get this moving. Could you address cubic's feedback and the comments I've left? The standalone CLI build needs fixing before this goes in. I also reproduced the compatibility issues cubic flagged, so let's make the migration plan explicit rather than treating this as an import-only change, especially where existing callers can silently lose data.

Comment thread cmd/openapi/go.mod
Comment thread go.mod

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 16 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Re-trigger cubic

Comment thread jsonpointer/jsonpointer.go Outdated
Comment thread linter/fix/legacy_fix_test.go Outdated
Comment thread sequencedmap/map.go Outdated
Comment thread jsonpointer/legacy_yaml_test.go Outdated
@AdamMagued

Copy link
Copy Markdown
Contributor Author

All requested review items and automated reviewer findings have been resolved:

  1. Standalone CLI Build & Pseudo-version Workflow:

    • Updated github.com/speakeasy-api/openapi and github.com/speakeasy-api/openapi/openapi/linter/customrules in cmd/openapi/go.mod to the updated pseudo-version following the documented multi-module workflow (v1.25.6-0.20261014041923-1f876e09ff4f).
    • Verified that standalone CLI compilation (GOWORK=off go build -C cmd/openapi .) succeeds without type mismatch errors between legacy and modern YAML nodes/styles.
  2. Formatting & Module Tidiness:

    • Sorted go.yaml.in/yaml/v3 v3.0.5 before golang.org/x/sync in go.mod.
    • Corrected import grouping and formatting in jsonschema/oas3/validation.go, marshaller/sequencedmap.go, marshaller/unmarshaller.go, sequencedmap/map.go, and jsonpointer/jsonpointer.go.
    • Verified both .mise-tasks/mod-check and .mise-tasks/fmt-check pass cleanly across all modules in the repository.
  3. SequencedMap Legacy Compatibility:

    • Documented the go.yaml.in/yaml/v3 contract on Map.UnmarshalYAML and Map.MarshalYAML.
    • Added LegacyYAMLAdapter[K, V] and Map.AsLegacyYAML() to satisfy gopkg.in/yaml.v3.Unmarshaler and Marshaler without data loss or leaking node internal fields (kind, style, content).
    • Extended Map.UnmarshalYAML and Map.MarshalYAML to bridge nested legacy value unmarshalers (UnmarshalYAML(*gopkg.in/yaml.v3.Node) error) and marshalers (MarshalYAML()), preventing data loss when map value types implement legacy YAML interfaces.
    • Added unit test coverage for round-trips, direct legacy unmarshaling behavior, and nested legacy value unmarshalers in sequencedmap/yaml_migration_test.go.
  4. JSONPointer, Values, and Linter Fix Bridge:

    • Preserved legacy result types in jsonpointer.GetTarget when navigating from legacy input nodes, returning *gopkg.in/yaml.v3.Node and asserting both node kind and resolved values in jsonpointer/legacy_yaml_test.go.
    • Added values.FromLegacyNode and values.ToLegacyNode zero-copy conversion helpers.
    • Added validation.LegacyNodeFix and updated the fix engine to invoke legacy node fixes, with test assertions on node kind and contents in linter/fix/legacy_fix_test.go.
    • Added compile-time layout guards and //nolint:gosec annotations on zero-copy pointer casts between identical yaml.Node memory layouts.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Re-trigger cubic

Comment thread sequencedmap/map.go Outdated
@TristanSpeakEasy

Copy link
Copy Markdown
Member

@AdamMagued almost there just some conflicts and last bit of cubic feedback to address

# Conflicts:
#	cmd/openapi/go.mod
#	cmd/openapi/go.sum
#	go.mod
#	internal/interfaces/interfaces_test.go
#	openapi/linter/customrules/go.mod

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval skipped because this PR is from an external contributor.

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval skipped because this PR is from an external contributor.

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval skipped because this PR is from an external contributor.

View guided diff | Re-trigger cubic

@TristanSpeakEasy

Copy link
Copy Markdown
Member

@AdamMagued I've picked this up to get it over the line. Rather than keeping the unsafe bridge between the old and new node types, I've migrated the dependencies that still used gopkg.in/yaml.v3, which let me remove the bridge entirely.

Dependencies

Removed from this PR

  • All the unsafe node casts, plus validation.LegacyNodeFix, values.FromLegacyNode/ToLegacyNode, sequencedmap.LegacyYAMLAdapter/AsLegacyYAML, and the legacy branches in jsonpointer, hashing and sequencedmap, along with their tests. Those files now match main apart from the import swap.
  • gopkg.in/yaml.v3 no longer appears in any of the repo's go.mod files, not even as an indirect dependency.

Before merging

fmt, mod-check, lint, examples, CLI integration tests and the build all pass locally, and the CLI builds standalone with GOWORK=off. The only test failures are 7 TestJSONSchemaTestSuite_RoundTrip cases, which fail the same way on main.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 24 files (changes from recent commits).

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Re-trigger cubic

Comment thread sequencedmap/map.go

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 9 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval skipped because this PR is from an external contributor.

View guided diff | Re-trigger cubic

@TristanSpeakEasy TristanSpeakEasy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Adam, this is good to go now that jsonpath and yamlpath are on go.yaml.in/yaml/v3 and the bridge code is gone.

@TristanSpeakEasy
TristanSpeakEasy added this pull request to the merge queue Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Merged via the queue into speakeasy-api:main with commit 5c1b54d Oct 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace gopkg.in/yaml.v3 with go.yaml.in/yaml/v3

2 participants