Skip to content

Commit 4a1f14b

Browse files
fix: to_sorbet_type should not return branded types
1 parent d7335ac commit 4a1f14b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/openai/internal/type/enum.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ def coerce(value, state:)
116116
#
117117
# @return [Object]
118118
def to_sorbet_type
119-
case values
119+
types = values.map { OpenAI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
120+
case types
120121
in []
121122
T.noreturn
122-
in [value, *_]
123-
T.all(OpenAI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(value), self)
123+
in [type]
124+
type
125+
else
126+
T.any(*types)
124127
end
125128
end
126129

lib/openai/internal/type/union.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,14 @@ def dump(value, state:)
220220
#
221221
# @return [Object]
222222
def to_sorbet_type
223-
case (v = variants)
223+
types = variants.map { OpenAI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
224+
case types
224225
in []
225226
T.noreturn
227+
in [type]
228+
type
226229
else
227-
T.any(*v.map { OpenAI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) })
230+
T.any(*types)
228231
end
229232
end
230233

lib/openai/models.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ module OpenAI
1111
mod.constants.each do |name|
1212
case mod.const_get(name)
1313
in true | false
14-
mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T.all(T::Boolean, mod) } }
14+
mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T::Boolean } }
1515
mod.define_sorbet_constant!(:OrBoolean) { T.type_alias { T::Boolean } }
1616
in Integer
17-
mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { T.all(Integer, mod) } }
17+
mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { Integer } }
1818
mod.define_sorbet_constant!(:OrInteger) { T.type_alias { Integer } }
1919
in Float
20-
mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { T.all(Float, mod) } }
20+
mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { Float } }
2121
mod.define_sorbet_constant!(:OrFloat) { T.type_alias { Float } }
2222
in Symbol
23-
mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { T.all(Symbol, mod) } }
23+
mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { Symbol } }
2424
mod.define_sorbet_constant!(:OrSymbol) { T.type_alias { T.any(Symbol, String) } }
2525
else
2626
end

0 commit comments

Comments
 (0)