Skip to content
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] Fix deserialize ApiException as a Model #757

Merged

Conversation

ymilin
Copy link
Contributor

@ymilin ymilin commented Aug 7, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

When defining default responses (ApiException) as a Schema Object in Swagger declaration files, the current implementation cannot deserialize the Model properly into ApiException::$responseObject.

Added a check for $returnType and json_decode appropriately (same logic as the try part of same function for success responses)

fix #756

@ymilin
Copy link
Contributor Author

ymilin commented Aug 7, 2018

@ymilin
Copy link
Contributor Author

ymilin commented Aug 7, 2018

Please note that this is a port of a PR from swagger-codegen#7968

This PR takes account of previous code reviews and takes another approach:

  • Move json_decode statements from api methods to the ObjectSerializer::deserialize method as it knows the data type and is already handling each cases separately.
  • Add tests to not json_decode on recursive calls of ObjectSerializer::deserialize

I successfully tested this PR against multiple response types (Model, Model[], map[string, int[]], array[int], bool, ...) with correct deserialisation of ApiException as a model.

@ackintosh
Copy link
Contributor

I've added a fix for the "petstore-security-test" sample.
(It is a fault from #681 , sorry 💦 )

@ackintosh
Copy link
Contributor

https://app.shippable.com/github/OpenAPITools/openapi-generator/runs/2088/1/console

There are uncommitted changes in working tree after execution of 'bin/ensure-up-to-date'
Perform git diff
diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php
index 340735ea2..ff500e699 100644
--- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php
+++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php
@@ -154,9 +154,6 @@ class AnotherFakeApi
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
.- if ('\OpenAPI\Client\Model\Client' !== 'string') {
.- $content = json_decode($content);
.- }
}

@ymilin Could you run /bin/openapi3/php-petstore.sh?

@ymilin
Copy link
Contributor Author

ymilin commented Aug 10, 2018

@ackintosh Thanks, just added a new commit.

@ackintosh ackintosh added this to the 3.3.0 milestone Sep 6, 2018
Copy link
Contributor

@ackintosh ackintosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

@ackintosh ackintosh merged commit c546323 into OpenAPITools:master Sep 6, 2018
@wing328
Copy link
Member

wing328 commented Oct 2, 2018

@ymilin thanks again for the PR, which is included in the v3.3.0 minor release: https://twitter.com/oas_generator/status/1046941449609068544

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* [PHP] Fix deserialize for default responses. Update samples

* [PHP] Update sample files

* Fix the distination ("-o") of petstore-security-test

* Clean up "petstore-security-test" folder

* Update petstore-security-test sample files

* Update petstore OpenAPI3 sample files
Caffe1neAdd1ct added a commit to zVPS/royal-mail-shipping-rest-api-client that referenced this pull request Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PHP] Bug deserialize default responses as a Model
3 participants