@@ -6,9 +6,9 @@ module StructuredOutput
66 # To customize the JSON schema conversion for a type, implement the `JsonSchemaConverter` interface.
77 module JsonSchemaConverter
88 # @api private
9- POINTER = Object . new . tap do
9+ POINTERS = Object . new . tap do
1010 _1 . define_singleton_method ( :inspect ) do
11- "#<#{ OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter } ::POINTER >"
11+ "#<#{ OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter } ::POINTERS >"
1212 end
1313 end . freeze
1414 # @api private
@@ -75,13 +75,15 @@ def to_nilable(schema)
7575 def cache_def! ( state , type :, &blk )
7676 defs , path = state . fetch_values ( :defs , :path )
7777 if ( stored = defs [ type ] )
78- pointers = stored . fetch ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTER )
79- pointers . first . except ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::NO_REF ) . tap { pointers << _1 }
78+ pointers = stored . fetch ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTERS )
79+ pointers . first . except ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::NO_REF ) . tap do
80+ pointers << _1
81+ end
8082 else
8183 ref_path = String . new
8284 ref = { "$ref" : ref_path }
8385 stored = {
84- OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTER => [ ref ]
86+ OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTERS => [ ref ]
8587 }
8688 defs . store ( type , stored )
8789 schema = blk . call
@@ -105,18 +107,18 @@ def to_json_schema(type)
105107 )
106108 reused_defs = { }
107109 defs . each_value do |acc |
108- sch = acc . except ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTER )
109- pointers = acc . fetch ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTER )
110+ sch = acc . except ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTERS )
111+ pointers = acc . fetch ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::POINTERS )
110112
111113 no_refs , refs = pointers . partition do
112114 _1 . delete ( OpenAI ::Helpers ::StructuredOutput ::JsonSchemaConverter ::NO_REF )
113115 end
114116
115117 case refs
116- in [ _ , ref , *]
117- reused_defs . store ( ref . fetch ( :$ref ) , sch )
118118 in [ ref ]
119119 ref . replace ( sch )
120+ in [ _ , ref , *]
121+ reused_defs . store ( ref . fetch ( :$ref ) , sch )
120122 else
121123 end
122124 no_refs . each { _1 . replace ( sch ) }
0 commit comments