MCPcopy
hub / github.com/openai/openai-go / MarshalWithExtras

Function MarshalWithExtras

packages/param/encoder.go:43–71  ·  view source on GitHub ↗

MarshalWithExtras is used to marshal a struct with additional properties. Stability for the API of MarshalWithExtras is not guaranteed.

(f T, underlying any, extras map[string]R)

Source from the content-addressed store, hash-verified

41//
42// Stability for the API of MarshalWithExtras is not guaranteed.
43func MarshalWithExtras[T ParamStruct, R any](f T, underlying any, extras map[string]R) ([]byte, error) {
44 if f.null() {
45 return []byte("null"), nil
46 } else if len(extras) > 0 {
47 bytes, err := shimjson.Marshal(underlying)
48 if err != nil {
49 return nil, err
50 }
51 for k, v := range extras {
52 var a any = v
53 if a == Omit {
54 // Errors when handling ForceOmitted are ignored.
55 if b, e := sjson.DeleteBytes(bytes, k); e == nil {
56 bytes = b
57 }
58 continue
59 }
60 bytes, err = sjson.SetBytes(bytes, EscapeSJSONKey(k), v)
61 if err != nil {
62 return nil, err
63 }
64 }
65 return bytes, nil
66 } else if ovr, ok := f.Overrides(); ok {
67 return shimjson.Marshal(ovr)
68 } else {
69 return shimjson.Marshal(underlying, shimjson.WithSkipCompaction(true))
70 }
71}
72
73// MarshalUnion uses a shimmed 'encoding/json' from Go 1.24, to support the 'omitzero' tag
74//

Callers 2

MarshalJSONMethod · 0.92
MarshalObjectFunction · 0.85

Calls 2

nullMethod · 0.65
OverridesMethod · 0.65

Tested by 1

MarshalJSONMethod · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…