feat: typed invalid_parameters and request editors in the v3 Go SDK - #4717
feat: typed invalid_parameters and request editors in the v3 Go SDK#4717tothandras wants to merge 1 commit into
Conversation
The SDK's APIError exposed only the five fixed problem-details fields, so reading the server's structured invalid_parameters meant hand-rolling a decode of RawBody. Add typed InvalidParameters to APIError: one flat InvalidParameter struct mirroring what the server serializes across all five spec variants (fields irrelevant to a rule stay zero), with string based Rule/Source types whose unknown values still decode and round-trip (check Valid() before assuming a known constant). Choices and Dependents are []any because the spec types them as unknown[]. Decoding stays the single best-effort json.Unmarshal in newAPIError. Add WithRequestEditor: per-request hooks (e.g. correlation IDs) without replacing the whole HTTP client. Editors run in newRequestWithContentType - the single choke point behind every generated operation - after all SDK-applied defaults including the per-operation Content-Type override, so an editor can override any header; an editor error aborts before any network call. Multiple editors compose in the order passed to New. All changes live in the @openmeter/typespec-go emitter (runtime templates, client component, reserved symbol registry); the SDK output is regenerated.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughThe Go SDK now exposes structured field-level validation errors and supports ordered request editors that can modify outgoing requests or abort request creation. TypeSpec Go templates, generated client code, runtime symbols, documentation, and tests reflect both additions. ChangesGo SDK runtime enhancements
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant RequestBuilder
participant RequestEditors
participant HTTPTransport
Client->>RequestBuilder: create outgoing request
RequestBuilder->>RequestEditors: apply configured editors after headers
RequestEditors-->>RequestBuilder: edited request or error
RequestBuilder->>HTTPTransport: send request
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The SDK's APIError exposed only the five fixed problem-details fields, so reading the server's structured invalid_parameters meant hand-rolling a decode of RawBody. Add typed InvalidParameters to APIError: one flat InvalidParameter struct mirroring what the server serializes across all five spec variants (fields irrelevant to a rule stay zero), with string based Rule/Source types whose unknown values still decode and round-trip (check Valid() before assuming a known constant). Choices and Dependents are []any because the spec types them as unknown[]. Decoding stays the single best-effort json.Unmarshal in newAPIError.
Add WithRequestEditor: per-request hooks (e.g. correlation IDs) without replacing the whole HTTP client. Editors run in newRequestWithContentType
All changes live in the @openmeter/typespec-go emitter (runtime templates, client component, reserved symbol registry); the SDK output is regenerated.
Summary by CodeRabbit
New Features
Documentation
Greptile Summary
This PR expands the generated v3 Go SDK error and request customization APIs. The main changes are:
APIError.Confidence Score: 5/5
This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "feat: typed invalid_parameters and reque..." | Re-trigger Greptile
Context used (3)