[Ruby] Fix regualr expression in error message (#2069) (#2139)

* Fix usage of regular expression literals in Ruby client (#2069)

* update samples of Ruby client (#2069)
This commit is contained in:
Akira Tanimura 2019-02-18 22:18:55 +09:00 committed by William Cheng
parent aace459217
commit 8d6278bd4c
6 changed files with 51 additions and 34 deletions

View File

@ -102,8 +102,9 @@ module {{moduleName}}
{{/minimum}}
{{#pattern}}
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ Regexp.new({{{pattern}}})
fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}."
pattern = Regexp.new({{{pattern}}})
if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ pattern
fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern #{pattern}."
end
{{/pattern}}

View File

@ -174,8 +174,9 @@
{{/minimum}}
{{#pattern}}
if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} !~ Regexp.new({{{pattern}}})
invalid_properties.push('invalid value for "{{{name}}}", must conform to the pattern {{{pattern}}}.')
pattern = Regexp.new({{{pattern}}})
if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}} !~ pattern
invalid_properties.push("invalid value for \"{{{name}}}\", must conform to the pattern #{pattern}.")
end
{{/pattern}}
@ -327,8 +328,9 @@
{{/minimum}}
{{#pattern}}
if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} !~ Regexp.new({{{pattern}}})
fail ArgumentError, 'invalid value for "{{{name}}}", must conform to the pattern {{{pattern}}}.'
pattern = Regexp.new({{{pattern}}})
if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}} !~ pattern
fail ArgumentError, "invalid value for \"{{{name}}}\", must conform to the pattern #{pattern}."
end
{{/pattern}}

View File

@ -492,8 +492,9 @@ module Petstore
if @api_client.config.client_side_validation && pattern_without_delimiter.nil?
fail ArgumentError, "Missing the required parameter 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters"
end
if @api_client.config.client_side_validation && pattern_without_delimiter !~ Regexp.new(/^[A-Z].*/)
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /^[A-Z].*/."
pattern = Regexp.new(/^[A-Z].*/)
if @api_client.config.client_side_validation && pattern_without_delimiter !~ pattern
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
end
# verify the required parameter 'byte' is set
@ -520,8 +521,9 @@ module Petstore
fail ArgumentError, 'invalid value for "opts[:"float"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 987.6.'
end
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ Regexp.new(/[a-z]/i)
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /[a-z]/i."
pattern = Regexp.new(/[a-z]/i)
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ pattern
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
end
if @api_client.config.client_side_validation && !opts[:'password'].nil? && opts[:'password'].to_s.length > 64

View File

@ -187,16 +187,18 @@ module Petstore
invalid_properties.push('invalid value for "double", must be greater than or equal to 67.8.')
end
if !@string.nil? && @string !~ Regexp.new(/[a-z]/i)
invalid_properties.push('invalid value for "string", must conform to the pattern /[a-z]/i.')
pattern = Regexp.new(/[a-z]/i)
if !@string.nil? && @string !~ pattern
invalid_properties.push("invalid value for \"string\", must conform to the pattern #{pattern}.")
end
if @byte.nil?
invalid_properties.push('invalid value for "byte", byte cannot be nil.')
end
if @byte !~ Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
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}=)?$/.')
pattern = Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
if @byte !~ pattern
invalid_properties.push("invalid value for \"byte\", must conform to the pattern #{pattern}.")
end
if @date.nil?
@ -319,8 +321,9 @@ module Petstore
# Custom attribute writer method with validation
# @param [Object] string Value to be assigned
def string=(string)
if !string.nil? && string !~ Regexp.new(/[a-z]/i)
fail ArgumentError, 'invalid value for "string", must conform to the pattern /[a-z]/i.'
pattern = Regexp.new(/[a-z]/i)
if !string.nil? && string !~ pattern
fail ArgumentError, "invalid value for \"string\", must conform to the pattern #{pattern}."
end
@string = string
@ -333,8 +336,9 @@ module Petstore
fail ArgumentError, 'byte cannot be nil'
end
if byte !~ Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
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}=)?$/.'
pattern = Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
if byte !~ pattern
fail ArgumentError, "invalid value for \"byte\", must conform to the pattern #{pattern}."
end
@byte = byte

View File

@ -493,8 +493,9 @@ module Petstore
if @api_client.config.client_side_validation && pattern_without_delimiter.nil?
fail ArgumentError, "Missing the required parameter 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters"
end
if @api_client.config.client_side_validation && pattern_without_delimiter !~ Regexp.new(/^[A-Z].*/)
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /^[A-Z].*/."
pattern = Regexp.new(/^[A-Z].*/)
if @api_client.config.client_side_validation && pattern_without_delimiter !~ pattern
fail ArgumentError, "invalid value for 'pattern_without_delimiter' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
end
# verify the required parameter 'byte' is set
@ -521,8 +522,9 @@ module Petstore
fail ArgumentError, 'invalid value for "opts[:"float"]" when calling FakeApi.test_endpoint_parameters, must be smaller than or equal to 987.6.'
end
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ Regexp.new(/[a-z]/i)
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern /[a-z]/i."
pattern = Regexp.new(/[a-z]/i)
if @api_client.config.client_side_validation && !opts[:'string'].nil? && opts[:'string'] !~ pattern
fail ArgumentError, "invalid value for 'opts[:\"string\"]' when calling FakeApi.test_endpoint_parameters, must conform to the pattern #{pattern}."
end
if @api_client.config.client_side_validation && !opts[:'password'].nil? && opts[:'password'].to_s.length > 64

View File

@ -205,8 +205,9 @@ module Petstore
invalid_properties.push('invalid value for "double", must be greater than or equal to 67.8.')
end
if !@string.nil? && @string !~ Regexp.new(/[a-z]/i)
invalid_properties.push('invalid value for "string", must conform to the pattern /[a-z]/i.')
pattern = Regexp.new(/[a-z]/i)
if !@string.nil? && @string !~ pattern
invalid_properties.push("invalid value for \"string\", must conform to the pattern #{pattern}.")
end
if @byte.nil?
@ -229,12 +230,14 @@ module Petstore
invalid_properties.push('invalid value for "password", the character length must be great than or equal to 10.')
end
if !@pattern_with_digits.nil? && @pattern_with_digits !~ Regexp.new(/^\d{10}$/)
invalid_properties.push('invalid value for "pattern_with_digits", must conform to the pattern /^\d{10}$/.')
pattern = Regexp.new(/^\d{10}$/)
if !@pattern_with_digits.nil? && @pattern_with_digits !~ pattern
invalid_properties.push("invalid value for \"pattern_with_digits\", must conform to the pattern #{pattern}.")
end
if !@pattern_with_digits_and_delimiter.nil? && @pattern_with_digits_and_delimiter !~ Regexp.new(/^image_\d{1,3}$/i)
invalid_properties.push('invalid value for "pattern_with_digits_and_delimiter", must conform to the pattern /^image_\d{1,3}$/i.')
pattern = Regexp.new(/^image_\d{1,3}$/i)
if !@pattern_with_digits_and_delimiter.nil? && @pattern_with_digits_and_delimiter !~ pattern
invalid_properties.push("invalid value for \"pattern_with_digits_and_delimiter\", must conform to the pattern #{pattern}.")
end
invalid_properties
@ -342,8 +345,9 @@ module Petstore
# Custom attribute writer method with validation
# @param [Object] string Value to be assigned
def string=(string)
if !string.nil? && string !~ Regexp.new(/[a-z]/i)
fail ArgumentError, 'invalid value for "string", must conform to the pattern /[a-z]/i.'
pattern = Regexp.new(/[a-z]/i)
if !string.nil? && string !~ pattern
fail ArgumentError, "invalid value for \"string\", must conform to the pattern #{pattern}."
end
@string = string
@ -370,8 +374,9 @@ module Petstore
# Custom attribute writer method with validation
# @param [Object] pattern_with_digits Value to be assigned
def pattern_with_digits=(pattern_with_digits)
if !pattern_with_digits.nil? && pattern_with_digits !~ Regexp.new(/^\d{10}$/)
fail ArgumentError, 'invalid value for "pattern_with_digits", must conform to the pattern /^\d{10}$/.'
pattern = Regexp.new(/^\d{10}$/)
if !pattern_with_digits.nil? && pattern_with_digits !~ pattern
fail ArgumentError, "invalid value for \"pattern_with_digits\", must conform to the pattern #{pattern}."
end
@pattern_with_digits = pattern_with_digits
@ -380,8 +385,9 @@ module Petstore
# Custom attribute writer method with validation
# @param [Object] pattern_with_digits_and_delimiter Value to be assigned
def pattern_with_digits_and_delimiter=(pattern_with_digits_and_delimiter)
if !pattern_with_digits_and_delimiter.nil? && pattern_with_digits_and_delimiter !~ Regexp.new(/^image_\d{1,3}$/i)
fail ArgumentError, 'invalid value for "pattern_with_digits_and_delimiter", must conform to the pattern /^image_\d{1,3}$/i.'
pattern = Regexp.new(/^image_\d{1,3}$/i)
if !pattern_with_digits_and_delimiter.nil? && pattern_with_digits_and_delimiter !~ pattern
fail ArgumentError, "invalid value for \"pattern_with_digits_and_delimiter\", must conform to the pattern #{pattern}."
end
@pattern_with_digits_and_delimiter = pattern_with_digits_and_delimiter