File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,19 @@ func Override[T ParamStruct, PtrT InferPtr[T]](v any) T {
4141 return * pt
4242}
4343
44+ // SetJSON configures a param struct to serialize with the provided raw JSON data.
45+ // Use this when you have existing JSON that you want to send as request parameters.
46+ //
47+ // var req example.NewUserParams
48+ // var rawJSON = []byte(`{"name": "...", "age": 40}`)
49+ // param.SetJSON(rawJSON, &req)
50+ // res, err := client.Users.New(ctx, req)
51+ //
52+ // Note: The struct's existing fields will be ignored; only the provided JSON is serialized.
53+ func SetJSON (rawJSON []byte , ptr anyParamStruct ) {
54+ ptr .setMetadata (json .RawMessage (rawJSON ))
55+ }
56+
4457// IsOmitted returns true if v is the zero value of its type.
4558//
4659// If IsOmitted is true, and the field uses a `json:"...,omitzero"` tag,
@@ -91,6 +104,11 @@ type ParamStruct interface {
91104 extraFields () map [string ]any
92105}
93106
107+ // A pointer to ParamStruct
108+ type anyParamStruct interface {
109+ setMetadata (any )
110+ }
111+
94112// This is an implementation detail and should never be explicitly set.
95113type InferPtr [T ParamStruct ] interface {
96114 setMetadata (any )
You can’t perform that action at this time.
0 commit comments