Skip to content

Conversation

akar016012
Copy link

This commit addresses issue #520 where the JSON unmarshaling fails for ChatCompletionToolChoiceOptionUnionParam
when encountering OfAuto field with param.Opt[string] type. The decoder.field.Type.Elem() method was calling
.Elem() on param.Opt[string] which is not a pointer type, causing unmarshaling to fail.

Modified files and changes:

  • chatcompletion.go:
    • Added custom UnmarshalJSON method for ChatCompletionToolChoiceOptionUnionParam
    • Implemented proper handling of simple string values for OfAuto field
    • Added discriminated object unmarshaling based on "type" field
    • Added support for "function", "allowed_tools", and "custom" types
    • Replaced generic apijson.UnmarshalRoot call with type-specific handling

This fix ensures that the union parameter can properly unmarshal both string values and complex objects
without encountering type reflection errors when dealing with param.Opt types.

…am unmarshaling

This commit addresses issue openai#520 where the JSON unmarshaling fails for ChatCompletionToolChoiceOptionUnionParam
when encountering OfAuto field with param.Opt[string] type. The decoder.field.Type.Elem() method was calling
.Elem() on param.Opt[string] which is not a pointer type, causing unmarshaling to fail.

Modified files and changes:
- chatcompletion.go:
  * Added custom UnmarshalJSON method for ChatCompletionToolChoiceOptionUnionParam
  * Implemented proper handling of simple string values for OfAuto field
  * Added discriminated object unmarshaling based on "type" field
  * Added support for "function", "allowed_tools", and "custom" types
  * Replaced generic apijson.UnmarshalRoot call with type-specific handling

This fix ensures that the union parameter can properly unmarshal both string values and complex objects
without encountering type reflection errors when dealing with param.Opt types.
@akar016012 akar016012 requested a review from a team as a code owner October 1, 2025 03:45
@akar016012
Copy link
Author

akar016012 commented Oct 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant