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

Method validatedTypeDecoder

internal/apijson/decoder.go:146–160  ·  view source on GitHub ↗

validatedTypeDecoder wraps the type decoder with a validator. This is helpful for ensuring that enum fields are correct.

(t reflect.Type, entry *validationEntry)

Source from the content-addressed store, hash-verified

144// validatedTypeDecoder wraps the type decoder with a validator. This is helpful
145// for ensuring that enum fields are correct.
146func (d *decoderBuilder) validatedTypeDecoder(t reflect.Type, entry *validationEntry) decoderFunc {
147 dec := d.typeDecoder(t)
148 if entry == nil {
149 return dec
150 }
151
152 // Thread the current validation entry through the decoder,
153 // but clean up in time for the next field.
154 return func(node gjson.Result, v reflect.Value, state *decoderState) error {
155 state.validator = entry
156 err := dec(node, v, state)
157 state.validator = nil
158 return err
159 }
160}
161
162func indirectUnmarshalerDecoder(n gjson.Result, v reflect.Value, state *decoderState) error {
163 return v.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(n.Raw))

Callers 1

newStructTypeDecoderMethod · 0.95

Calls 1

typeDecoderMethod · 0.95

Tested by

no test coverage detected