[BUG] [php-symfony] Response Content for Status-Codes >= 300 ignored
Created by: HCrane
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When returning a Status code above 300 the result won't be sent to the user in the request body although explicitly stated in the *.yaml file used for generation
openapi-generator version
4.2.3
OpenAPI declaration file content or url
Minimized yaml
file can be found here: https://gist.github.com/dmetzner/3b5d2e3f1ce637a618d932563dc5cbcb
Command line used for generation
java -jar ../openapi-generator-cli.jar generate \
-i testing.yaml \
-g php-symfony \
-p sortParamsByRequiredFlag=true \
-p skipFormModel=true \
-p variableNamingConvention=camelCase \
-p phpLegacySupport=false
Steps to reproduce
Just generating with the given yaml file, and looking directly in ./Controller/UserController.php
.
At the end of the function you should see something like this:
$result = $handler->userPost($inlineObject, $responseCode, $responseHeaders);
// Find default response message
$message = 'User successfully registered.';
// Find a more specific message, if available
switch ($responseCode) {
case 201:
$message = 'User successfully registered.';
break;
case 400:
$message = 'BAD Request - invalid or missing required parameters';
break;
case 415:
$message = 'Unsupported Media Type - request must use application/json as content type';
break;
case 422:
$message = 'Unprocessable Entity';
break;
}
return new Response(
'',
$responseCode,
array_merge(
$responseHeaders,
[
'X-OpenAPI-Message' => $message
]
)
);
As you can see result is simply ignored.
Related issues/PRs
Not to my knowledge no.
Suggest a fix
It should look like a response from a 200 Status code like this:
return new Response(
$result !== null ?$this->serialize($result, $responseFormat):'',
$responseCode,
array_merge(
$responseHeaders,
[
'Content-Type' => $responseFormat,
'X-OpenAPI-Message' => $message
]
)
);