OpenAPITools / OpenAPITools/openapi-generator
[BUG] [php-symfony] Response Content for Status-Codes >= 300 ignored
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
]
)
);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimized YAML declaration and run the shown OpenAPI Generator command for php-symfony. Inspect the generated ./Controller/UserController.php, especially the response returned for status codes 300 and above. Done means the generated response includes the serialized result, status code, headers, and message for those responses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php, symfony
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100