You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
namespace App\Controller;
use OpenAPI\Server\Api\DefaultApiInterface;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Writer\PngWriter;
class DefaultApi implements DefaultApiInterface {
public function getBoolGet(int &$responseCode, array &$responseHeaders): array|object|null {
return true;
}
// I'm using composer package "endroid/qr-code" to generate a png
public function getImageGet(int &$responseCode, array &$responseHeaders): array|object|null {
$builder = new Builder(writer: new PngWriter(), data: "some qr code");
return $builder->build()->getString();
}
public function getIntGet(int &$responseCode, array &$responseHeaders): array|object|null {
return 1312;
}
public function getNumberGet(int &$responseCode, array &$responseHeaders): array|object|null {
return 13.12;
}
public function getStringGet(int &$responseCode, array &$responseHeaders): array|object|null {
return "hello world!";
}
}
then try to query any of those endpoints.
The generated code replies with a 406 instead of the expected response. (But there are actually 3 issues, and the 406 is just the first one that reveals itself. More details below).
Related issues/PRs
This is bit similar to #13334 but this report is more generic because #13334 identifies only one of the three actual issues (see below).
Similarly the open PR #15560 tries to address part of the issue, but it's only a partial fix of one of the issue
Suggest a fix
There are 3 things that needs to be fixed:
The generated method Controller.getOutputFormat should be able to return more type than just application/json or application/xml (that's the reason why we have a 406)
The generated methods of DefaultController should properly define the expected return type (see snippet above: what I return does not match array|object|null). This should be done by handling those other types in PhpSymfonyServerCodegen.java in the method postProcessOperationsWIthModels, when x-return-type is set
in JmsSerializer.serialize it should not try to call ->serialize($data, ...) when the 2nd argument is null, otherwise it crashes at runtime (error 500) because the type of that 2nd argument is declared to be a string.
I'm going to submit shortly a PR that implements those 3 fixes
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Bug Report Checklist
Description
openapi-generator version
I tested with 7.12.0 and also with the latest
master
OpenAPI declaration file content or url
This has 5 endpoints. Each of those endpoint illustrates the issue, but each with a different return type (so the fix can be tested against each)
Generation Details
java -jar openapi-generator-cli.jar generate --git-user-id "some-user" --git-repo-id "some-project" -i "openapi.yaml" -g php-symfony -o "generated"
Steps to reproduce
Implement a simple symfony controller like this:
then try to query any of those endpoints.
The generated code replies with a 406 instead of the expected response. (But there are actually 3 issues, and the 406 is just the first one that reveals itself. More details below).
Related issues/PRs
This is bit similar to #13334 but this report is more generic because #13334 identifies only one of the three actual issues (see below).
Similarly the open PR #15560 tries to address part of the issue, but it's only a partial fix of one of the issue
Suggest a fix
There are 3 things that needs to be fixed:
Controller.getOutputFormat
should be able to return more type than justapplication/json
orapplication/xml
(that's the reason why we have a 406)DefaultController
should properly define the expected return type (see snippet above: what I return does not matcharray|object|null
). This should be done by handling those other types inPhpSymfonyServerCodegen.java
in the methodpostProcessOperationsWIthModels
, whenx-return-type
is setJmsSerializer.serialize
it should not try to call->serialize($data, ...)
when the 2nd argument is null, otherwise it crashes at runtime (error 500) because the type of that 2nd argument is declared to be a string.I'm going to submit shortly a PR that implements those 3 fixes
The text was updated successfully, but these errors were encountered: