Skip to content

refactor: decouple mongodb driver from root module#222

Merged
fredbi merged 2 commits intogo-openapi:masterfrom
fredbi:refactor/decouple-mongodb
Mar 7, 2026
Merged

refactor: decouple mongodb driver from root module#222
fredbi merged 2 commits intogo-openapi:masterfrom
fredbi:refactor/decouple-mongodb

Conversation

@fredbi
Copy link
Member

@fredbi fredbi commented Mar 7, 2026

Drop go.mongodb.org/mongo-driver/v2 from the root go.mod by introducing an internal minimal BSON codec (bsonlite) that is wire-compatible with mongo-driver v2.5.0. Users who want the real driver can opt in with a blank import: import _ "github.com/go-openapi/strfmt/enable/mongodb".

  • internal/bsonlite: minimal BSON encoder/decoder for string, DateTime, ObjectID document types (no external dependencies)
  • enable/mongodb: separate Go module that replaces the lite codec with the real mongo-driver via init()
  • ObjectId type changed from bsonprim.ObjectID to [12]byte (same underlying type, backward compatible)
  • All BSON marshal/unmarshal methods rewritten to use bsonlite.C interface
  • Convert to mono-repo: go.work, CI workflows switched to monorepo variants (ci-workflows v0.2.13), dependabot scans all modules
  • Integration tests verify both codec paths against real MongoDB

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

* fixes go-openapi#91
* relates to go-openapi#191

Drop go.mongodb.org/mongo-driver/v2 from the root go.mod by introducing
an internal minimal BSON codec (bsonlite) that is wire-compatible with
mongo-driver v2.5.0. Users who want the real driver can opt in with a
blank import: `import _ "github.com/go-openapi/strfmt/enable/mongodb"`.

- internal/bsonlite: minimal BSON encoder/decoder for string, DateTime,
  ObjectID document types (no external dependencies)
- enable/mongodb: separate Go module that replaces the lite codec with
  the real mongo-driver via init()
- ObjectId type changed from bsonprim.ObjectID to [12]byte (same
  underlying type, backward compatible)
- All BSON marshal/unmarshal methods rewritten to use bsonlite.C interface
- Convert to mono-repo: go.work, CI workflows switched to monorepo
  variants (ci-workflows v0.2.13), dependabot scans all modules
- Integration tests verify both codec paths against real MongoDB

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 67.53623% with 112 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.30%. Comparing base (7304ce1) to head (21159c0).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
mongo.go 69.18% 16 Missing and 37 partials ⚠️
internal/bsonlite/lite.go 76.85% 16 Missing and 9 partials ⚠️
enable/mongodb/mongodb.go 0.00% 22 Missing ⚠️
bson.go 65.51% 5 Missing and 5 partials ⚠️
internal/bsonlite/codec.go 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #222      +/-   ##
==========================================
- Coverage   85.01%   83.30%   -1.72%     
==========================================
  Files          14       17       +3     
  Lines        2016     2150     +134     
==========================================
+ Hits         1714     1791      +77     
- Misses        218      257      +39     
- Partials       84      102      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The go.mod directive (go 1.24) causes setup-go to install go1.24.0,
which triggers a panic in testify/v2 goroutine leak detector init().
Use go-version: stable (go1.26) until testify is patched.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi fredbi merged commit 435a1e4 into go-openapi:master Mar 7, 2026
20 checks passed
@fredbi fredbi deleted the refactor/decouple-mongodb branch March 7, 2026 21:26
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.

Consider removing mongo-db-driver dependency

1 participant