Skip to content

handle missing case properly #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion internal/apijson/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Field struct {
status status
}

// Returns true if the field is explicitly `null` _or_ if it is not present at all (ie, missing).
// IsNull returns true if the field is explicitly `null` _or_ if it is not present at all (ie, missing).
// To check if the field's key is present in the JSON with an explicit null value,
// you must check `f.IsNull() && !f.IsMissing()`.
func (j Field) IsNull() bool { return j.status <= null }
Expand Down
9 changes: 5 additions & 4 deletions internal/apijson/subfield.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package apijson

import (
"github.com/openai/openai-go/packages/resp"
"reflect"

"github.com/openai/openai-go/packages/resp"
)

func getSubField(root reflect.Value, index []int, name string) reflect.Value {
Expand Down Expand Up @@ -55,10 +56,10 @@ func setMetadataExtraFields(root reflect.Value, index []int, name string, metaEx
}

func (f Field) toRespField() resp.Field {
if f.IsNull() {
return resp.NewNullField()
} else if f.IsMissing() {
if f.IsMissing() {
return resp.Field{}
} else if f.IsNull() {
return resp.NewNullField()
} else if f.IsInvalid() {
return resp.NewInvalidField(f.raw)
} else {
Expand Down