-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PHP] Bug deserialize default responses as a Model #7544
Comments
any updates? |
thanks @ymilin , i'll take a time this week to review your PR. |
Hi @kamynina, I did try and submit a PR for this issue here Code review (thanks @wing328) showed that my fix is causing issues with primitive type responses and I promised to spend more time on it for a definitive fix. Since then, I couldn't find more time to come back to it but I'm pretty confident I will be able to somewhere this summer 🤷♂️ @HugoMario , Edit: try {
...
} catch (ApiException $e) {
$errorModel = ObjectSerializer::deserialize(
json_decode($e->getResponseBody()),
\Foo\ErrorModel::class,
$e->getResponseHeaders()
);
// $errorModel is an instance of \Foo\ErrorModel
} |
Description
I'm generating clients that make use of
default
responses for other HTTP codes (implying an error). It's defined as a Model (code, message) indefinitions
in the swagger file.After generating the client API with swagger-codegen, when catching an
ApiException
, the deserialized response objectApiException::responseObject
is empty (it is an an instance ofErrorModel
as expected, but with no content).Swagger-codegen version
2.3.0
Swagger declaration file content or url
gist: minimal swagger.json example
Command line used for generation
Steps to reproduce
With the generated client:
$e->getResponseObject()
to be a fully hydrated instance of ErrorModelSuggest a fix/enhancement
I checked the generated code and the bug seem to be located in the
catch
part of the{{operationId}}WithHttpInfo
methods:We can see that there is a specific test for this in the
try
part of same function in theapi.mustache
file, line 164swagger-codegen/modules/swagger-codegen/src/main/resources/php/api.mustache
Lines 163 to 166 in 36f69a0
So a possible fix would be doing something similar when deserializing for
ApiException
objects.I can work on a PR for this, as I really need it, but I have no experience with mustache templates and will not be able to test edge cases.
So I would need help for testing my PR.
The text was updated successfully, but these errors were encountered: