Skip to content

feat: typed invalid_parameters and request editors in the v3 Go SDK - #4717

Open
tothandras wants to merge 1 commit into
mainfrom
feat/go-sdk-invalid-parameters-request-editor
Open

feat: typed invalid_parameters and request editors in the v3 Go SDK#4717
tothandras wants to merge 1 commit into
mainfrom
feat/go-sdk-invalid-parameters-request-editor

Conversation

@tothandras

@tothandras tothandras commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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.

Summary by CodeRabbit

  • New Features

    • Added support for customizing outgoing requests with request editors, including header and content-type overrides.
    • Added structured parsing of field-level validation details from HTTP 400 responses.
    • Expanded API errors with invalid parameter sources, rules, bounds, choices, and dependent fields.
  • Documentation

    • Updated error-handling guidance to describe detailed validation errors and problem fields.

Greptile Summary

This PR expands the generated v3 Go SDK error and request customization APIs. The main changes are:

  • Adds typed field-level validation details to APIError.
  • Preserves unknown validation rules and sources for forward compatibility.
  • Adds ordered request editors that run after SDK headers are applied.
  • Updates generator templates, generated output, documentation, and tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The generated output matches the emitter templates.
  • All generated operations use the request path that invokes editors.
  • The new error types match the current TypeSpec and server wire shapes.

Important Files Changed

Filename Overview
api/spec/packages/typespec-go/src/runtime-templates.ts Adds the error types, request editor API, ordered execution, and wrapped error propagation to the Go runtime templates.
api/spec/packages/typespec-go/src/components/GoClient.tsx Adds request editor storage to emitted clients.
api/spec/packages/typespec-go/src/runtime-symbols.ts Reserves the new runtime type, constant, and option names against generated symbol collisions.
api/v3/client/errors.go Adds typed decoding for the current invalid-parameter wire variants while retaining the raw response body.
api/v3/client/request_content_type.go Runs request editors after SDK defaults and before transport execution.
api/v3/client/option.go Adds ordered, nil-safe registration of request editors during client construction.
api/v3/client/errors_test.go Covers each typed validation variant, unknown rules, absent data, and malformed field-level data.
api/v3/client/transport_test.go Covers editor ordering, header overrides, context propagation, nil handling, and pre-transport errors.

Reviews (1): Last reviewed commit: "feat: typed invalid_parameters and reque..." | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - AGENTS.md (source)
  • Context used - api/spec/AGENTS.md (source)

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.
@tothandras
tothandras requested a review from a team as a code owner July 15, 2026 14:52
@tothandras tothandras added the release-note/feature Release note: Exciting New Features label Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e956bab4-e4a0-424c-96a7-4533cef601c2

📥 Commits

Reviewing files that changed from the base of the PR and between 4aea250 and 8cba218.

📒 Files selected for processing (11)
  • api/spec/packages/typespec-go/src/components/GoClient.tsx
  • api/spec/packages/typespec-go/src/readme.ts
  • api/spec/packages/typespec-go/src/runtime-symbols.ts
  • api/spec/packages/typespec-go/src/runtime-templates.ts
  • api/v3/client/README.md
  • api/v3/client/client.go
  • api/v3/client/errors.go
  • api/v3/client/errors_test.go
  • api/v3/client/option.go
  • api/v3/client/request_content_type.go
  • api/v3/client/transport_test.go

📝 Walkthrough

Walkthrough

The 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.

Changes

Go SDK runtime enhancements

Layer / File(s) Summary
Structured validation error model
api/spec/packages/typespec-go/src/runtime-templates.ts, api/spec/packages/typespec-go/src/runtime-symbols.ts, api/v3/client/errors.go, api/v3/client/errors_test.go, api/spec/packages/typespec-go/src/readme.ts, api/v3/client/README.md
APIError now carries best-effort typed InvalidParameters data, including validation sources, rules, optional bounds, choices, dependents, and validity checks. Templates, reserved symbols, documentation, and decoding tests are updated.
Request editor pipeline
api/spec/packages/typespec-go/src/components/GoClient.tsx, api/spec/packages/typespec-go/src/runtime-templates.ts, api/spec/packages/typespec-go/src/runtime-symbols.ts, api/v3/client/client.go, api/v3/client/option.go, api/v3/client/request_content_type.go, api/v3/client/transport_test.go
Clients accept ordered non-nil RequestEditorFn options, run editors after default request setup, allow request modifications, and return wrapped errors before transport on failure. Tests cover ordering, overrides, context propagation, nil editors, and abort behavior.

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
Loading

Suggested labels: kind/feature

Suggested reviewers: galexihu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: typed invalid_parameters support and request editors in the v3 Go SDK.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/go-sdk-invalid-parameters-request-editor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant