Skip to content

Commit 5902af4

Browse files
authored
in case of defined status codes > 299 switch will have no effect. issue 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
1 parent 39fb510 commit 5902af4

File tree

28 files changed

+1274
-1776
lines changed

28 files changed

+1274
-1776
lines changed

modules/openapi-generator/src/main/resources/php-nextgen/api.mustache

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,6 @@ use {{invokerPackage}}\ObjectSerializer;
286286

287287
$statusCode = $response->getStatusCode();
288288

289-
if ($statusCode < 200 || $statusCode > 299) {
290-
throw new ApiException(
291-
sprintf(
292-
'[%d] Error connecting to the API (%s)',
293-
$statusCode,
294-
(string) $request->getUri()
295-
),
296-
$statusCode,
297-
$response->getHeaders(),
298-
(string) $response->getBody()
299-
);
300-
}
301289
{{#returnType}}
302290
{{#responses}}
303291
{{#-first}}
@@ -338,6 +326,19 @@ use {{invokerPackage}}\ObjectSerializer;
338326
{{/-last}}
339327
{{/responses}}
340328

329+
if ($statusCode < 200 || $statusCode > 299) {
330+
throw new ApiException(
331+
sprintf(
332+
'[%d] Error connecting to the API (%s)',
333+
$statusCode,
334+
(string) $request->getUri()
335+
),
336+
$statusCode,
337+
$response->getHeaders(),
338+
(string) $response->getBody()
339+
);
340+
}
341+
341342
$returnType = '{{{returnType}}}';
342343
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
343344
$content = $response->getBody(); //stream goes to serializer

modules/openapi-generator/src/main/resources/php/api.mustache

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,6 @@ use {{invokerPackage}}\ObjectSerializer;
254254

255255
$statusCode = $response->getStatusCode();
256256

257-
if ($statusCode < 200 || $statusCode > 299) {
258-
throw new ApiException(
259-
sprintf(
260-
'[%d] Error connecting to the API (%s)',
261-
$statusCode,
262-
(string) $request->getUri()
263-
),
264-
$statusCode,
265-
$response->getHeaders(),
266-
(string) $response->getBody()
267-
);
268-
}
269257
{{#returnType}}
270258
{{#responses}}
271259
{{#-first}}
@@ -306,6 +294,19 @@ use {{invokerPackage}}\ObjectSerializer;
306294
{{/-last}}
307295
{{/responses}}
308296

297+
if ($statusCode < 200 || $statusCode > 299) {
298+
throw new ApiException(
299+
sprintf(
300+
'[%d] Error connecting to the API (%s)',
301+
$statusCode,
302+
(string) $request->getUri()
303+
),
304+
$statusCode,
305+
$response->getHeaders(),
306+
(string) $response->getBody()
307+
);
308+
}
309+
309310
$returnType = '{{{returnType}}}';
310311
if ($returnType === '\SplFileObject') {
311312
$content = $response->getBody(); //stream goes to serializer

samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,6 @@ public function testAuthHttpBasicWithHttpInfo(
184184

185185
$statusCode = $response->getStatusCode();
186186

187-
if ($statusCode < 200 || $statusCode > 299) {
188-
throw new ApiException(
189-
sprintf(
190-
'[%d] Error connecting to the API (%s)',
191-
$statusCode,
192-
(string) $request->getUri()
193-
),
194-
$statusCode,
195-
$response->getHeaders(),
196-
(string) $response->getBody()
197-
);
198-
}
199187

200188
switch($statusCode) {
201189
case 200:
@@ -227,6 +215,19 @@ public function testAuthHttpBasicWithHttpInfo(
227215
];
228216
}
229217

218+
if ($statusCode < 200 || $statusCode > 299) {
219+
throw new ApiException(
220+
sprintf(
221+
'[%d] Error connecting to the API (%s)',
222+
$statusCode,
223+
(string) $request->getUri()
224+
),
225+
$statusCode,
226+
$response->getHeaders(),
227+
(string) $response->getBody()
228+
);
229+
}
230+
230231
$returnType = 'string';
231232
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
232233
$content = $response->getBody(); //stream goes to serializer
@@ -485,18 +486,6 @@ public function testAuthHttpBearerWithHttpInfo(
485486

486487
$statusCode = $response->getStatusCode();
487488

488-
if ($statusCode < 200 || $statusCode > 299) {
489-
throw new ApiException(
490-
sprintf(
491-
'[%d] Error connecting to the API (%s)',
492-
$statusCode,
493-
(string) $request->getUri()
494-
),
495-
$statusCode,
496-
$response->getHeaders(),
497-
(string) $response->getBody()
498-
);
499-
}
500489

501490
switch($statusCode) {
502491
case 200:
@@ -528,6 +517,19 @@ public function testAuthHttpBearerWithHttpInfo(
528517
];
529518
}
530519

520+
if ($statusCode < 200 || $statusCode > 299) {
521+
throw new ApiException(
522+
sprintf(
523+
'[%d] Error connecting to the API (%s)',
524+
$statusCode,
525+
(string) $request->getUri()
526+
),
527+
$statusCode,
528+
$response->getHeaders(),
529+
(string) $response->getBody()
530+
);
531+
}
532+
531533
$returnType = 'string';
532534
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
533535
$content = $response->getBody(); //stream goes to serializer

0 commit comments

Comments
 (0)