Skip to content

feat: v1 API cleanup with helpers and improved JSON handling#5

Merged
michaelpeterswa merged 1 commit into
mainfrom
feat/v1-cleanup
May 8, 2026
Merged

feat: v1 API cleanup with helpers and improved JSON handling#5
michaelpeterswa merged 1 commit into
mainfrom
feat/v1-cleanup

Conversation

@michaelpeterswa

@michaelpeterswa michaelpeterswa commented May 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Drops mapstructure in favor of custom MarshalJSON/UnmarshalJSON, fixes several usability issues, and adds convenience helpers.
  • Adds FromError, status-named constructors (BadRequest, NotFound, etc.), and makes *RFC9457 satisfy the error interface.
  • Releasing as a minor bump (v1.x) intentionally rather than cutting a /v2 module path, even though some signatures change for callers — see "API changes" below.

Behavior changes

  • ServeHTTP defaults Status to 500 when unset; writes a minimal fallback body if serialization fails.
  • Title and Instance now use omitempty.
  • WithExtensions is additive across calls.
  • Extension keys colliding with reserved members (type, status, title, detail, instance) return ErrExtensionKeyCollision.
  • FromJSON populates Type with "about:blank" when missing, per the RFC.

API additions

  • FromError(err, status) to wrap a Go error.
  • *RFC9457 implements error (nil-safe).
  • Status-named constructors: BadRequest, Unauthorized, Forbidden, NotFound, MethodNotAllowed, Conflict, Gone, UnprocessableEntity, TooManyRequests, InternalServerError, NotImplemented, BadGateway, ServiceUnavailable, GatewayTimeout.
  • Compile-time interface assertions for error, http.Handler, json.Marshaler, json.Unmarshaler.
  • doc.go package overview.

API changes

Signatures break callers but this lands as a minor bump intentionally:

  • ToJSON now returns []byte (was string).
  • FromJSON now accepts []byte (was string).
  • Write() removed — use ServeHTTP (already implements http.Handler).
  • RFC9457Error (int iota) replaced with sentinel errors: ErrUnableToMarshalJSON, ErrUnableToUnmarshalJSON, ErrExtensionKeyCollision. The translate-* variants are removed along with mapstructure.

Test plan

  • go vet ./...
  • go build ./...
  • go test ./... — all green
  • go mod tidymapstructure removed
  • Confirm CI (commitlint, golangci-lint, yamllint, test matrix) passes on the PR

🤖 Generated with Claude Code

Drop the mapstructure dependency in favor of custom MarshalJSON /
UnmarshalJSON, fix a handful of usability issues, and add convenience
helpers for the common cases.

Behavior changes:
- ServeHTTP defaults Status to 500 when unset and writes a minimal
  fallback problem body if serialization fails.
- Title and Instance now use omitempty.
- WithExtensions is additive across calls.
- Extension keys colliding with reserved members return
  ErrExtensionKeyCollision instead of being silently dropped.
- FromJSON populates Type with "about:blank" when missing, per the RFC.

API additions:
- FromError(err, status) wraps a Go error as a problem.
- *RFC9457 implements the error interface (nil-safe).
- Status-named constructors: BadRequest, Unauthorized, Forbidden,
  NotFound, MethodNotAllowed, Conflict, Gone, UnprocessableEntity,
  TooManyRequests, InternalServerError, NotImplemented, BadGateway,
  ServiceUnavailable, GatewayTimeout.
- Compile-time assertions for error, http.Handler, json.Marshaler,
  and json.Unmarshaler.
- doc.go with a package overview.

API changes (note: signatures break callers but this lands as a minor
bump intentionally rather than cutting a /v2 module path):
- ToJSON now returns []byte instead of string.
- FromJSON now accepts []byte instead of string.
- The redundant Write() method is removed (use ServeHTTP).
- RFC9457Error (int iota) is replaced with sentinel errors:
  ErrUnableToMarshalJSON, ErrUnableToUnmarshalJSON,
  ErrExtensionKeyCollision. The translate-* variants are removed
  alongside mapstructure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@michaelpeterswa michaelpeterswa changed the title feat!: v1 API cleanup with helpers and improved JSON handling feat: v1 API cleanup with helpers and improved JSON handling May 8, 2026
@michaelpeterswa michaelpeterswa merged commit 0bfdee3 into main May 8, 2026
5 checks passed
@michaelpeterswa

Copy link
Copy Markdown
Member Author

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant