Skip to content

Commit 7bafde9

Browse files
committed
update samples of Ruby client (#2069)
1 parent 14592cd commit 7bafde9

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

samples/client/petstore/ruby/lib/petstore/api/fake_api.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,9 @@ def test_endpoint_parameters_with_http_info(number, double, pattern_without_deli
492492
if @api_client.config.client_side_validation && pattern_without_delimiter.nil?
493493
fail ArgumentError, "Missing the required parameter 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters"
494494
end
495-
if @api_client.config.client_side_validation && pattern_without_delimiter !~ Regexp.new(/^[A-Z].*/)
496-
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /^[A-Z].*/."
495+
pattern = Regexp.new(/^[A-Z].*/)
496+
if @api_client.config.client_side_validation && pattern_without_delimiter !~ pattern
497+
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
497498
end
498499

499500
# verify the required parameter 'byte' is set
@@ -520,8 +521,9 @@ def test_endpoint_parameters_with_http_info(number, double, pattern_without_deli
520521
fail ArgumentError, 'invalid value for "opts[:"float"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 987.6.'
521522
end
522523

523-
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ Regexp.new(/[a-z]/i)
524-
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /[a-z]/i."
524+
pattern = Regexp.new(/[a-z]/i)
525+
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ pattern
526+
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
525527
end
526528

527529
if @api_client.config.client_side_validation && !opts[:'password'].nil? && opts[:'password'].to_s.length > 64

samples/client/petstore/ruby/lib/petstore/models/format_test.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,18 @@ def list_invalid_properties
187187
invalid_properties.push('invalid value for "double", must be greater than or equal to 67.8.')
188188
end
189189

190-
if !@string.nil? && @string !~ Regexp.new(/[a-z]/i)
191-
invalid_properties.push('invalid value for "string", must conform to the pattern /[a-z]/i.')
190+
pattern = Regexp.new(/[a-z]/i)
191+
if !@string.nil? && @string !~ pattern
192+
invalid_properties.push("invalid value for \"string\", must conform to the pattern #{pattern}.")
192193
end
193194

194195
if @byte.nil?
195196
invalid_properties.push('invalid value for "byte", byte cannot be nil.')
196197
end
197198

198-
if @byte !~ Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
199-
invalid_properties.push('invalid value for "byte", must conform to the pattern /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.')
199+
pattern = Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
200+
if @byte !~ pattern
201+
invalid_properties.push("invalid value for \"byte\", must conform to the pattern #{pattern}.")
200202
end
201203

202204
if @date.nil?
@@ -319,8 +321,9 @@ def double=(double)
319321
# Custom attribute writer method with validation
320322
# @param [Object] string Value to be assigned
321323
def string=(string)
322-
if !string.nil? && string !~ Regexp.new(/[a-z]/i)
323-
fail ArgumentError, 'invalid value for "string", must conform to the pattern /[a-z]/i.'
324+
pattern = Regexp.new(/[a-z]/i)
325+
if !string.nil? && string !~ pattern
326+
fail ArgumentError, "invalid value for \"string\", must conform to the pattern #{pattern}."
324327
end
325328

326329
@string = string
@@ -333,8 +336,9 @@ def byte=(byte)
333336
fail ArgumentError, 'byte cannot be nil'
334337
end
335338

336-
if byte !~ Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
337-
fail ArgumentError, 'invalid value for "byte", must conform to the pattern /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.'
339+
pattern = Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
340+
if byte !~ pattern
341+
fail ArgumentError, "invalid value for \"byte\", must conform to the pattern #{pattern}."
338342
end
339343

340344
@byte = byte

samples/openapi3/client/petstore/ruby/lib/petstore/api/fake_api.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ def test_endpoint_parameters_with_http_info(number, double, pattern_without_deli
448448
if @api_client.config.client_side_validation && pattern_without_delimiter.nil?
449449
fail ArgumentError, "Missing the required parameter 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters"
450450
end
451-
if @api_client.config.client_side_validation && pattern_without_delimiter !~ Regexp.new(/^[A-Z].*/)
452-
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /^[A-Z].*/."
451+
pattern = Regexp.new(/^[A-Z].*/)
452+
if @api_client.config.client_side_validation && pattern_without_delimiter !~ pattern
453+
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
453454
end
454455

455456
# verify the required parameter 'byte' is set
@@ -476,8 +477,9 @@ def test_endpoint_parameters_with_http_info(number, double, pattern_without_deli
476477
fail ArgumentError, 'invalid value for "opts[:"float"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 987.6.'
477478
end
478479

479-
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ Regexp.new(/[a-z]/i)
480-
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /[a-z]/i."
480+
pattern = Regexp.new(/[a-z]/i)
481+
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ pattern
482+
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
481483
end
482484

483485
if @api_client.config.client_side_validation && !opts[:'password'].nil? && opts[:'password'].to_s.length > 64

samples/openapi3/client/petstore/ruby/lib/petstore/models/format_test.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ def list_invalid_properties
205205
invalid_properties.push('invalid value for "double", must be greater than or equal to 67.8.')
206206
end
207207

208-
if !@string.nil? && @string !~ Regexp.new(/[a-z]/i)
209-
invalid_properties.push('invalid value for "string", must conform to the pattern /[a-z]/i.')
208+
pattern = Regexp.new(/[a-z]/i)
209+
if !@string.nil? && @string !~ pattern
210+
invalid_properties.push("invalid value for \"string\", must conform to the pattern #{pattern}.")
210211
end
211212

212213
if @byte.nil?
@@ -229,12 +230,14 @@ def list_invalid_properties
229230
invalid_properties.push('invalid value for "password", the character length must be great than or equal to 10.')
230231
end
231232

232-
if !@pattern_with_digits.nil? && @pattern_with_digits !~ Regexp.new(/^\d{10}$/)
233-
invalid_properties.push('invalid value for "pattern_with_digits", must conform to the pattern /^\d{10}$/.')
233+
pattern = Regexp.new(/^\d{10}$/)
234+
if !@pattern_with_digits.nil? && @pattern_with_digits !~ pattern
235+
invalid_properties.push("invalid value for \"pattern_with_digits\", must conform to the pattern #{pattern}.")
234236
end
235237

236-
if !@pattern_with_digits_and_delimiter.nil? && @pattern_with_digits_and_delimiter !~ Regexp.new(/^image_\d{1,3}$/i)
237-
invalid_properties.push('invalid value for "pattern_with_digits_and_delimiter", must conform to the pattern /^image_\d{1,3}$/i.')
238+
pattern = Regexp.new(/^image_\d{1,3}$/i)
239+
if !@pattern_with_digits_and_delimiter.nil? && @pattern_with_digits_and_delimiter !~ pattern
240+
invalid_properties.push("invalid value for \"pattern_with_digits_and_delimiter\", must conform to the pattern #{pattern}.")
238241
end
239242

240243
invalid_properties
@@ -342,8 +345,9 @@ def double=(double)
342345
# Custom attribute writer method with validation
343346
# @param [Object] string Value to be assigned
344347
def string=(string)
345-
if !string.nil? && string !~ Regexp.new(/[a-z]/i)
346-
fail ArgumentError, 'invalid value for "string", must conform to the pattern /[a-z]/i.'
348+
pattern = Regexp.new(/[a-z]/i)
349+
if !string.nil? && string !~ pattern
350+
fail ArgumentError, "invalid value for \"string\", must conform to the pattern #{pattern}."
347351
end
348352

349353
@string = string
@@ -370,8 +374,9 @@ def password=(password)
370374
# Custom attribute writer method with validation
371375
# @param [Object] pattern_with_digits Value to be assigned
372376
def pattern_with_digits=(pattern_with_digits)
373-
if !pattern_with_digits.nil? && pattern_with_digits !~ Regexp.new(/^\d{10}$/)
374-
fail ArgumentError, 'invalid value for "pattern_with_digits", must conform to the pattern /^\d{10}$/.'
377+
pattern = Regexp.new(/^\d{10}$/)
378+
if !pattern_with_digits.nil? && pattern_with_digits !~ pattern
379+
fail ArgumentError, "invalid value for \"pattern_with_digits\", must conform to the pattern #{pattern}."
375380
end
376381

377382
@pattern_with_digits = pattern_with_digits
@@ -380,8 +385,9 @@ def pattern_with_digits=(pattern_with_digits)
380385
# Custom attribute writer method with validation
381386
# @param [Object] pattern_with_digits_and_delimiter Value to be assigned
382387
def pattern_with_digits_and_delimiter=(pattern_with_digits_and_delimiter)
383-
if !pattern_with_digits_and_delimiter.nil? && pattern_with_digits_and_delimiter !~ Regexp.new(/^image_\d{1,3}$/i)
384-
fail ArgumentError, 'invalid value for "pattern_with_digits_and_delimiter", must conform to the pattern /^image_\d{1,3}$/i.'
388+
pattern = Regexp.new(/^image_\d{1,3}$/i)
389+
if !pattern_with_digits_and_delimiter.nil? && pattern_with_digits_and_delimiter !~ pattern
390+
fail ArgumentError, "invalid value for \"pattern_with_digits_and_delimiter\", must conform to the pattern #{pattern}."
385391
end
386392

387393
@pattern_with_digits_and_delimiter = pattern_with_digits_and_delimiter

0 commit comments

Comments
 (0)