From ab8d62214aec6dcabaa77a5878fa75b9677c140f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 19 Mar 2015 20:58:22 +0800 Subject: [PATCH] add attributemap to php model, update php petstore sample --- .../src/main/resources/php/Swagger.mustache | 5 +++-- .../src/main/resources/php/model.mustache | 7 ++++++- samples/client/petstore/php/Swagger.php | 5 +++-- samples/client/petstore/php/models/Category.php | 7 ++++++- samples/client/petstore/php/models/Order.php | 11 ++++++++++- samples/client/petstore/php/models/Pet.php | 11 ++++++++++- samples/client/petstore/php/models/Tag.php | 7 ++++++- samples/client/petstore/php/models/User.php | 13 ++++++++++++- 8 files changed, 56 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache index 0f92ac8a0c0..3d6b77d819e 100644 --- a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache @@ -182,7 +182,7 @@ class APIClient { } else if (is_object($data)) { $values = array(); foreach (array_keys($data::$swaggerTypes) as $property) { - $values[$property] = $this->sanitizeForSerialization($data->$property); + $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property); } $sanitized = $values; } else { @@ -295,7 +295,8 @@ class APIClient { $instance = new $class(); foreach ($instance::$swaggerTypes as $property => $type) { if (isset($data->$property)) { - $instance->$property = self::deserialize($data->$property, $type); + $original_property_name = $instance::$attributeMap[$property]; + $instance->$property = self::deserialize($data->$original_property_name, $type); } } $deserialized = $instance; diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index f11a1547169..4540f973633 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -28,7 +28,12 @@ class {{classname}} implements ArrayAccess { static $swaggerTypes = array( {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, {{/hasMore}}{{/vars}} - ); + ); + + static $attributeMap = array( + {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); {{#vars}}{{#description}} /** diff --git a/samples/client/petstore/php/Swagger.php b/samples/client/petstore/php/Swagger.php index 0f92ac8a0c0..3d6b77d819e 100644 --- a/samples/client/petstore/php/Swagger.php +++ b/samples/client/petstore/php/Swagger.php @@ -182,7 +182,7 @@ class APIClient { } else if (is_object($data)) { $values = array(); foreach (array_keys($data::$swaggerTypes) as $property) { - $values[$property] = $this->sanitizeForSerialization($data->$property); + $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property); } $sanitized = $values; } else { @@ -295,7 +295,8 @@ class APIClient { $instance = new $class(); foreach ($instance::$swaggerTypes as $property => $type) { if (isset($data->$property)) { - $instance->$property = self::deserialize($data->$property, $type); + $original_property_name = $instance::$attributeMap[$property]; + $instance->$property = self::deserialize($data->$original_property_name, $type); } } $deserialized = $instance; diff --git a/samples/client/petstore/php/models/Category.php b/samples/client/petstore/php/models/Category.php index acd9004d882..98e7ba24800 100644 --- a/samples/client/petstore/php/models/Category.php +++ b/samples/client/petstore/php/models/Category.php @@ -26,7 +26,12 @@ class Category implements ArrayAccess { static $swaggerTypes = array( 'id' => 'int', 'name' => 'string' - ); + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); public $id; /* int */ diff --git a/samples/client/petstore/php/models/Order.php b/samples/client/petstore/php/models/Order.php index c7abef02d61..519e44bf217 100644 --- a/samples/client/petstore/php/models/Order.php +++ b/samples/client/petstore/php/models/Order.php @@ -30,7 +30,16 @@ class Order implements ArrayAccess { 'shipDate' => 'DateTime', 'status' => 'string', 'complete' => 'boolean' - ); + ); + + static $attributeMap = array( + 'id' => 'id', + 'petId' => 'petId', + 'quantity' => 'quantity', + 'shipDate' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); public $id; /* int */ diff --git a/samples/client/petstore/php/models/Pet.php b/samples/client/petstore/php/models/Pet.php index f8fa832cf8b..ad427e91a87 100644 --- a/samples/client/petstore/php/models/Pet.php +++ b/samples/client/petstore/php/models/Pet.php @@ -30,7 +30,16 @@ class Pet implements ArrayAccess { 'photoUrls' => 'array[string]', 'tags' => 'array[Tag]', 'status' => 'string' - ); + ); + + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photoUrls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); public $id; /* int */ diff --git a/samples/client/petstore/php/models/Tag.php b/samples/client/petstore/php/models/Tag.php index bb85524762c..f8efc998df6 100644 --- a/samples/client/petstore/php/models/Tag.php +++ b/samples/client/petstore/php/models/Tag.php @@ -26,7 +26,12 @@ class Tag implements ArrayAccess { static $swaggerTypes = array( 'id' => 'int', 'name' => 'string' - ); + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); public $id; /* int */ diff --git a/samples/client/petstore/php/models/User.php b/samples/client/petstore/php/models/User.php index 7cdff02ad03..6799a001558 100644 --- a/samples/client/petstore/php/models/User.php +++ b/samples/client/petstore/php/models/User.php @@ -32,7 +32,18 @@ class User implements ArrayAccess { 'password' => 'string', 'phone' => 'string', 'userStatus' => 'int' - ); + ); + + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'firstName' => 'firstName', + 'lastName' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'userStatus' => 'userStatus' + ); public $id; /* int */