Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ func handleDefaultConstValue(tagValue string, val interface{}, tag reflect.Struc
return []byte(fmt.Sprintf("%q", tagValue))
}
}

if !json.Valid([]byte(tagValue)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[suggestion] handleDefaultConstValue — add a companion test for any other OptionalNullable[EnumType] field with a string default: tag (e.g. ChatRequest.ServiceTier) to confirm no analogous case was missed

Details

The fix is correct and covers all callers of handleDefaultConstValue (lines 230, 291, 297 in json.go). Since ChatRequest.ServiceTier is *ChatRequestServiceTier (a plain pointer, not OptionalNullable[T]), it already hits the typ.Kind() == reflect.String branch and is unaffected. No action required — noting for completeness.

Prompt for agents
In `models/components/responsesrequest_test.go`, the test covers `ResponsesRequest.ServiceTier` (type `OptionalNullable[ResponsesRequestServiceTier]`). Optionally add a parallel test for `ChatRequest.ServiceTier` in `models/components/chatrequest_test.go` to document that the `*ChatRequestServiceTier` (pointer, not OptionalNullable) type is already handled correctly by the existing `Kind == String` branch. This is low priority — the fix in `internal/utils/json.go:448` covers all callers.

Reviewed at 19c9125

return []byte(fmt.Sprintf("%q", tagValue))
}

return []byte(tagValue)
}
Expand Down
33 changes: 33 additions & 0 deletions models/components/responsesrequest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package components_test

import (
"bytes"
"encoding/json"
"testing"

openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
)

func TestResponsesRequestMarshalWithoutServiceTier(t *testing.T) {
req := components.ResponsesRequest{
Input: openrouter.Pointer(
components.CreateInputsUnionStr("Hey there"),
),
Model: openrouter.Pointer("openai/gpt-4o-mini"),
Stream: openrouter.Bool(false),
}

b, err := json.Marshal(req)
if err != nil {
t.Fatalf("marshal failed: %v", err)
}

if !json.Valid(b) {
t.Fatalf("invalid JSON: %s", string(b))
}

if !bytes.Contains(b, []byte(`"service_tier":"auto"`)) {
t.Fatalf("expected service_tier default to be marshaled as string auto, got: %s", string(b))
}
}