diff --git a/modules/openapi-generator/src/main/resources/php/Configuration.mustache b/modules/openapi-generator/src/main/resources/php/Configuration.mustache index 32de830191c..35a4ab5c5e8 100644 --- a/modules/openapi-generator/src/main/resources/php/Configuration.mustache +++ b/modules/openapi-generator/src/main/resources/php/Configuration.mustache @@ -474,7 +474,7 @@ class Configuration $hosts = $this->getHostSettings(); // check array index out of bound - if ($index < 0 || $index > sizeof($hosts)) { + if ($index < 0 || $index >= sizeof($hosts)) { throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts)); } diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php index 641f72e7663..e9c5da06eab 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Configuration.php @@ -458,7 +458,7 @@ class Configuration $hosts = $this->getHostSettings(); // check array index out of bound - if ($index < 0 || $index > sizeof($hosts)) { + if ($index < 0 || $index >= sizeof($hosts)) { throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts)); } diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php index 42a68f7a3e0..a45e571f6fb 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Configuration.php @@ -491,7 +491,7 @@ class Configuration $hosts = $this->getHostSettings(); // check array index out of bound - if ($index < 0 || $index > sizeof($hosts)) { + if ($index < 0 || $index >= sizeof($hosts)) { throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts)); } diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/tests/ConfigurationTest.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/tests/ConfigurationTest.php index 983b871fd40..4b2738841b4 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/tests/ConfigurationTest.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/tests/ConfigurationTest.php @@ -41,6 +41,17 @@ class ConfigurationTest extends TestCase $this->assertSame("http://dev-petstore.swagger.io:8080/v2", $url); } + /** + * Test invalid index + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Invalid index 2 when selecting the host. Must be less than 2 + */ + public function testInvalidIndex() + { + $config = new Configuration(); + $url = $config->getHostFromSettings(2); + } + /** * Test host settings with invalid vaues * @expectedException InvalidArgumentException