@@ -94,7 +94,9 @@ def fields
94
94
end
95
95
rescue StandardError
96
96
cls = self . class . name . split ( "::" ) . last
97
+ # rubocop:disable Layout/LineLength
97
98
message = "Failed to parse #{ cls } .#{ __method__ } from #{ value . class } to #{ target . inspect } . To get the unparsed API response, use #{ cls } [:#{ __method__ } ]."
99
+ # rubocop:enable Layout/LineLength
98
100
raise OpenAI ::ConversionError . new ( message )
99
101
end
100
102
end
@@ -205,14 +207,13 @@ def coerce(value, state:)
205
207
instance = new
206
208
data = instance . to_h
207
209
210
+ # rubocop:disable Metrics/BlockLength
208
211
fields . each do |name , field |
209
212
mode , required , target = field . fetch_values ( :mode , :required , :type )
210
213
api_name , nilable , const = field . fetch_values ( :api_name , :nilable , :const )
211
214
212
215
unless val . key? ( api_name )
213
- if const != OpenAI ::Util ::OMIT
214
- exactness [ :yes ] += 1
215
- elsif required && mode != :dump
216
+ if required && mode != :dump && const == OpenAI ::Util ::OMIT
216
217
exactness [ nilable ? :maybe : :no ] += 1
217
218
else
218
219
exactness [ :yes ] += 1
@@ -238,6 +239,7 @@ def coerce(value, state:)
238
239
end
239
240
data . store ( name , converted )
240
241
end
242
+ # rubocop:enable Metrics/BlockLength
241
243
242
244
keys . each { data . store ( _1 , val . fetch ( _1 ) ) }
243
245
instance
0 commit comments