Skip to content

Commit

Permalink
in case of defined status codes > 299 switch will have no effect. iss…
Browse files Browse the repository at this point in the history
…ue 7788 (#19483)

* in case of defined status codes > 299 switch will have no effect. As described in issue 7788

so we get only an error if statusCode is not defined AND not between 200 and 299

#7788

* in case of defined status codes > 299 switch will have no effect. As described in issue 7788

so we get only an error if statusCode is not defined AND not between 200 and 299

#7788
  • Loading branch information
kruegge82 authored Oct 7, 2024
1 parent 39fb510 commit 5902af4
Show file tree
Hide file tree
Showing 28 changed files with 1,274 additions and 1,776 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,6 @@ use {{invokerPackage}}\ObjectSerializer;

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}
{{#returnType}}
{{#responses}}
{{#-first}}
Expand Down Expand Up @@ -338,6 +326,19 @@ use {{invokerPackage}}\ObjectSerializer;
{{/-last}}
{{/responses}}

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

$returnType = '{{{returnType}}}';
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
$content = $response->getBody(); //stream goes to serializer
Expand Down
25 changes: 13 additions & 12 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,6 @@ use {{invokerPackage}}\ObjectSerializer;

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}
{{#returnType}}
{{#responses}}
{{#-first}}
Expand Down Expand Up @@ -306,6 +294,19 @@ use {{invokerPackage}}\ObjectSerializer;
{{/-last}}
{{/responses}}

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

$returnType = '{{{returnType}}}';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
Expand Down
50 changes: 26 additions & 24 deletions samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,6 @@ public function testAuthHttpBasicWithHttpInfo(

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

switch($statusCode) {
case 200:
Expand Down Expand Up @@ -227,6 +215,19 @@ public function testAuthHttpBasicWithHttpInfo(
];
}

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

$returnType = 'string';
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
$content = $response->getBody(); //stream goes to serializer
Expand Down Expand Up @@ -485,18 +486,6 @@ public function testAuthHttpBearerWithHttpInfo(

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

switch($statusCode) {
case 200:
Expand Down Expand Up @@ -528,6 +517,19 @@ public function testAuthHttpBearerWithHttpInfo(
];
}

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

$returnType = 'string';
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
$content = $response->getBody(); //stream goes to serializer
Expand Down
Loading

0 comments on commit 5902af4

Please sign in to comment.