Skip to content

Commit

Permalink
[PHP] Fix deserialize ApiException as a Model (#757)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
ymilin authored and ackintosh committed Sep 6, 2018
1 parent a8cbae4 commit c546323
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 324 deletions.
2 changes: 1 addition & 1 deletion bin/security/php-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g php -o samples/client/petstore-security-test/php $@"
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g php -o samples/client/petstore-security-test/php/OpenAPIClient-php $@"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class ObjectSerializer
if (null === $data) {
return null;
} elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
$data = is_string($data) ? json_decode($data) : $data;
settype($data, 'array');
$inner = substr($class, 4, -1);
$deserialized = [];
if (strrpos($inner, ",") !== false) {
Expand All @@ -231,6 +233,7 @@ class ObjectSerializer
}
return $deserialized;
} elseif (strcasecmp(substr($class, -2), '[]') === 0) {
$data = is_string($data) ? json_decode($data) : $data;
$subClass = substr($class, 0, -2);
$values = [];
foreach ($data as $key => $value) {
Expand Down Expand Up @@ -280,6 +283,7 @@ class ObjectSerializer
}
return $data;
} else {
$data = is_string($data) ? json_decode($data) : $data;
// If a discriminator is defined and points to a valid subclass, use it.
$discriminator = $class::DISCRIMINATOR;
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
Expand Down
9 changes: 0 additions & 9 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ use {{invokerPackage}}\ObjectSerializer;
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('{{dataType}}' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -188,9 +185,6 @@ use {{invokerPackage}}\ObjectSerializer;
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -280,9 +274,6 @@ use {{invokerPackage}}\ObjectSerializer;
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.1-SNAPSHOT
3.2.1-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Method | HTTP request | Description
To test code injection *_/ ' \" =end -- \\r\\n \\n \\r

To test code injection *_/ ' \" =end -- \\r\\n \\n \\r

### Example
```php
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
* Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 3.1.1-SNAPSHOT
* OpenAPI Generator version: 3.2.0-SNAPSHOT
*/

/**
Expand Down Expand Up @@ -230,6 +230,8 @@ public static function deserialize($data, $class, $httpHeaders = null)
if (null === $data) {
return null;
} elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
$data = is_string($data) ? json_decode($data) : $data;
settype($data, 'array');
$inner = substr($class, 4, -1);
$deserialized = [];
if (strrpos($inner, ",") !== false) {
Expand All @@ -241,6 +243,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
}
return $deserialized;
} elseif (strcasecmp(substr($class, -2), '[]') === 0) {
$data = is_string($data) ? json_decode($data) : $data;
$subClass = substr($class, 0, -2);
$values = [];
foreach ($data as $key => $value) {
Expand Down Expand Up @@ -290,6 +293,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
}
return $data;
} else {
$data = is_string($data) ? json_decode($data) : $data;
// If a discriminator is defined and points to a valid subclass, use it.
$discriminator = $class::DISCRIMINATOR;
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public function call123TestSpecialTagsWithHttpInfo($client)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('\OpenAPI\Client\Model\Client' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -172,9 +169,6 @@ public function call123TestSpecialTagsWithHttpInfo($client)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -242,9 +236,6 @@ function ($response) use ($returnType) {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
45 changes: 0 additions & 45 deletions samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('bool' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -168,9 +165,6 @@ public function fakeOuterBooleanSerializeWithHttpInfo($body = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -238,9 +232,6 @@ function ($response) use ($returnType) {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -416,9 +407,6 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('\OpenAPI\Client\Model\OuterComposite' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -434,9 +422,6 @@ public function fakeOuterCompositeSerializeWithHttpInfo($outer_composite = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -504,9 +489,6 @@ function ($response) use ($returnType) {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -682,9 +664,6 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('float' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -700,9 +679,6 @@ public function fakeOuterNumberSerializeWithHttpInfo($body = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -770,9 +746,6 @@ function ($response) use ($returnType) {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -948,9 +921,6 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('string' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -966,9 +936,6 @@ public function fakeOuterStringSerializeWithHttpInfo($body = null)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1036,9 +1003,6 @@ function ($response) use ($returnType) {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1663,9 +1627,6 @@ public function testClientModelWithHttpInfo($client)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ('\OpenAPI\Client\Model\Client' !== 'string') {
$content = json_decode($content);
}
}

return [
Expand All @@ -1681,9 +1642,6 @@ public function testClientModelWithHttpInfo($client)
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down Expand Up @@ -1751,9 +1709,6 @@ function ($response) use ($returnType) {
$content = $responseBody; //stream goes to serializer
} else {
$content = $responseBody->getContents();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
Expand Down
Loading

0 comments on commit c546323

Please sign in to comment.