diff --git a/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache b/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache index dcfb0004228..d0d190ff2f5 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache @@ -261,8 +261,8 @@ module {{moduleName}} servers = server_settings # check array index out of bound - if (index < 0 || index > servers.size) - fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" + if (index < 0 || index >= servers.size) + fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" end server = servers[index] diff --git a/samples/client/petstore/ruby/lib/petstore/configuration.rb b/samples/client/petstore/ruby/lib/petstore/configuration.rb index e560956b89e..71376ac3848 100644 --- a/samples/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore/ruby/lib/petstore/configuration.rb @@ -245,8 +245,8 @@ module Petstore servers = server_settings # check array index out of bound - if (index < 0 || index > servers.size) - fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" + if (index < 0 || index >= servers.size) + fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" end server = servers[index] diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb index 586e02c6264..908147a4978 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb @@ -278,8 +278,8 @@ module Petstore servers = server_settings # check array index out of bound - if (index < 0 || index > servers.size) - fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" + if (index < 0 || index >= servers.size) + fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" end server = servers[index] diff --git a/samples/openapi3/client/petstore/ruby/spec/configuration_spec.rb b/samples/openapi3/client/petstore/ruby/spec/configuration_spec.rb index e666b7bc004..b45eeea4d0a 100644 --- a/samples/openapi3/client/petstore/ruby/spec/configuration_spec.rb +++ b/samples/openapi3/client/petstore/ruby/spec/configuration_spec.rb @@ -51,5 +51,9 @@ describe Petstore::Configuration do it 'should raise error due to invalid enum value' do expect{config.server_url(1, version: "v6")}.to raise_error(ArgumentError) end + + it 'should raise error due to invalid index' do + expect{config.server_url(2)}.to raise_error(ArgumentError) + end end end