Skip to content
Merged
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 .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.35.1"
".": "0.35.2"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.35.2 (2025-11-05)

Full Changelog: [v0.35.1...v0.35.2](https://github.com/openai/openai-ruby/compare/v0.35.1...v0.35.2)

### Bug Fixes

* better thread safety via early initializing SSL store during HTTP client creation ([e7d9a3d](https://github.com/openai/openai-ruby/commit/e7d9a3d70c0930ac248b4da680296213cb3e163d))
* schema generation ([#862](https://github.com/openai/openai-ruby/issues/862)) ([2c9b91a](https://github.com/openai/openai-ruby/commit/2c9b91acc79262dd56ef52854ad64384f172984b))

## 0.35.1 (2025-11-04)

Full Changelog: [v0.35.0...v0.35.1](https://github.com/openai/openai-ruby/compare/v0.35.0...v0.35.1)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
openai (0.35.1)
openai (0.35.2)
connection_pool

GEM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "openai", "~> 0.35.1"
gem "openai", "~> 0.35.2"
```

<!-- x-release-please-end -->
Expand Down
1 change: 1 addition & 0 deletions lib/openai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require "etc"
require "json"
require "net/http"
require "openssl"
require "pathname"
require "rbconfig"
require "securerandom"
Expand Down
6 changes: 5 additions & 1 deletion lib/openai/helpers/structured_output/union_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class UnionOf
#
# @return [Hash{Symbol=>Object}]
def to_json_schema_inner(state:)
# rubocop:disable Metrics/BlockLength
OpenAI::Helpers::StructuredOutput::JsonSchemaConverter.cache_def!(state, type: self) do
path = state.fetch(:path)
mergeable_keys = {[:anyOf] => 0, [:type] => 0}
Expand All @@ -33,7 +34,9 @@ def to_json_schema_inner(state:)
end

schemas.each do |schema|
mergeable_keys.each_key { mergeable_keys[_1] += 1 if schema.keys == _1 }
mergeable_keys.each_key do
mergeable_keys[_1] += 1 if schema.keys == _1 && schema[_1].is_a?(Array)
end
end
mergeable = mergeable_keys.any? { _1.last == schemas.length }
if mergeable
Expand All @@ -48,6 +51,7 @@ def to_json_schema_inner(state:)
}
end
end
# rubocop:enable Metrics/BlockLength
end

private_class_method :new
Expand Down
8 changes: 6 additions & 2 deletions lib/openai/internal/transport/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class PooledNetRequester
class << self
# @api private
#
# @param cert_store [OpenSSL::X509::Store]
# @param url [URI::Generic]
#
# @return [Net::HTTP]
def connect(url)
def connect(cert_store:, url:)
port =
case [url.port, url.scheme]
in [Integer, _]
Expand All @@ -33,6 +34,8 @@ def connect(url)
Net::HTTP.new(url.host, port).tap do
_1.use_ssl = %w[https wss].include?(url.scheme)
_1.max_retries = 0

(_1.cert_store = cert_store) if _1.use_ssl?
end
end

Expand Down Expand Up @@ -102,7 +105,7 @@ def build_request(request, &blk)
pool =
@mutex.synchronize do
@pools[origin] ||= ConnectionPool.new(size: @size) do
self.class.connect(url)
self.class.connect(cert_store: @cert_store, url: url)
end
end

Expand Down Expand Up @@ -192,6 +195,7 @@ def execute(request)
def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
@mutex = Mutex.new
@size = size
@cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
@pools = {}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/openai/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OpenAI
VERSION = "0.35.1"
VERSION = "0.35.2"
end
1 change: 1 addition & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
- etc
- json
- net/http
- openssl
- pathname
- rbconfig
- securerandom
Expand Down
8 changes: 6 additions & 2 deletions rbi/openai/internal/transport/pooled_net_requester.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ module OpenAI

class << self
# @api private
sig { params(url: URI::Generic).returns(Net::HTTP) }
def connect(url)
sig do
params(cert_store: OpenSSL::X509::Store, url: URI::Generic).returns(
Net::HTTP
)
end
def connect(cert_store:, url:)
end

# @api private
Expand Down
5 changes: 4 additions & 1 deletion sig/openai/internal/transport/pooled_net_requester.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ module OpenAI

DEFAULT_MAX_CONNECTIONS: Integer

def self.connect: (URI::Generic url) -> top
def self.connect: (
cert_store: OpenSSL::X509::Store,
url: URI::Generic
) -> top

def self.calibrate_socket_timeout: (top conn, Float deadline) -> void

Expand Down
7 changes: 7 additions & 0 deletions test/openai/helpers/structured_output_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class M3 < OpenAI::Helpers::StructuredOutput::BaseModel
U1 = OpenAI::Helpers::StructuredOutput::UnionOf[Integer, A1]
U2 = OpenAI::Helpers::StructuredOutput::UnionOf[M2, M3]
U3 = OpenAI::Helpers::StructuredOutput::UnionOf[A1, A1]
U4 = OpenAI::Helpers::StructuredOutput::UnionOf[String, NilClass]

def test_coerce
cases = {
Expand Down Expand Up @@ -117,6 +118,12 @@ def test_to_schema
additionalProperties: false
}
]
},
U4 => {
anyOf: [
{type: "string"},
{type: "null"}
]
}
}
cases.each do |input, expected|
Expand Down