diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SymfonyServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SymfonyServerCodegen.java index ae9cbd81fdf..8f30fd0f5f0 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SymfonyServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SymfonyServerCodegen.java @@ -140,7 +140,7 @@ public SymfonyServerCodegen() { typeMapping.put("map", "array"); typeMapping.put("array", "array"); typeMapping.put("list", "array"); - typeMapping.put("object", "object"); + typeMapping.put("object", "array"); typeMapping.put("binary", "string"); typeMapping.put("ByteArray", "string"); typeMapping.put("UUID", "string"); @@ -346,6 +346,16 @@ public Map postProcessOperations(Map objs) { param.vendorExtensions.put("x-parameterType", typeHint); } + if (param.isContainer) { + param.vendorExtensions.put("x-parameterType", getTypeHint(param.dataType+"[]")); + } + + // Create a variable to display the correct data type in comments for interfaces + param.vendorExtensions.put("x-commentType", param.dataType); + if (param.isContainer) { + param.vendorExtensions.put("x-commentType", param.dataType+"[]"); + } + // Quote default values for strings // @todo: The default values for headers, forms and query params are handled // in DefaultCodegen fromParameter with no real possibility to override @@ -355,16 +365,14 @@ public Map postProcessOperations(Map objs) { } } - for (CodegenResponse response : op.responses) { - final String exception = SYMFONY_EXCEPTIONS.get(response.code); - response.vendorExtensions.put("x-symfonyException", exception); - response.vendorExtensions.put("x-symfonyExceptionSimple", extractSimpleName(exception)); - - // Add simple return type to response - if (response.dataType != null) { - final String dataType = extractSimpleName(response.dataType); - response.vendorExtensions.put("x-simpleName", dataType); + // Create a variable to display the correct return type in comments for interfaces + if (op.returnType != null) { + op.vendorExtensions.put("x-commentType", op.returnType); + if (!op.returnTypeIsPrimitive) { + op.vendorExtensions.put("x-commentType", op.returnType+"[]"); } + } else { + op.vendorExtensions.put("x-commentType", "void"); } // Add operation's authentication methods to whole interface @@ -396,6 +404,12 @@ public Map postProcessModels(Map objs) { var.vendorExtensions.put("x-parameterType", typeHint); } + // Create a variable to display the correct data type in comments for models + var.vendorExtensions.put("x-commentType", var.datatype); + if (var.isContainer) { + var.vendorExtensions.put("x-commentType", var.datatype+"[]"); + } + if (var.isBoolean) { var.getter = var.getter.replaceAll("^get", "is"); } @@ -448,13 +462,13 @@ public String getTypeDeclaration(Property p) { if (p instanceof ArrayProperty) { ArrayProperty ap = (ArrayProperty) p; Property inner = ap.getItems(); - return getTypeDeclaration(inner) + "[]"; + return getTypeDeclaration(inner); } if (p instanceof MapProperty) { MapProperty mp = (MapProperty) p; Property inner = mp.getAdditionalProperties(); - return getTypeDeclaration(inner) + "[]"; + return getTypeDeclaration(inner); } if (p instanceof RefProperty) { diff --git a/modules/swagger-codegen/src/main/resources/php-symfony/api.mustache b/modules/swagger-codegen/src/main/resources/php-symfony/api.mustache index 0e581a1b84d..49d24a41cbd 100644 --- a/modules/swagger-codegen/src/main/resources/php-symfony/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php-symfony/api.mustache @@ -57,15 +57,13 @@ interface {{classname}} * {{/description}} {{#allParams}} - * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + * @param {{vendorExtensions.x-commentType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} {{/allParams}} * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - {{#returnType}} - * @return {{{returnType}}} + * @return {{{vendorExtensions.x-commentType}}} * - {{/returnType}} */ public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameterType}}{{vendorExtensions.x-parameterType}} {{/vendorExtensions.x-parameterType}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}&$responseCode, array &$responseHeaders); {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/php-symfony/api_controller.mustache b/modules/swagger-codegen/src/main/resources/php-symfony/api_controller.mustache index 6f21a082eb5..dde510fb5c9 100644 --- a/modules/swagger-codegen/src/main/resources/php-symfony/api_controller.mustache +++ b/modules/swagger-codegen/src/main/resources/php-symfony/api_controller.mustache @@ -99,12 +99,11 @@ class {{controllerName}} extends Controller {{/authMethods}} // Read out all input parameter values into variables - {{#allParams}} {{#queryParams}} ${{paramName}} = $request->query->get('{{paramName}}'); {{/queryParams}} {{#headerParams}} - ${{paramName}} = $request->headers->get('{{paramName}}'); + ${{paramName}} = $request->headers->get('{{baseName}}'); {{/headerParams}} {{#formParams}} {{#isFile}} @@ -135,14 +134,14 @@ class {{controllerName}} extends Controller {{/required}} // Deserialize the input values that needs it + {{#allParams}} {{^isFile}} - {{#bodyParams}} - - ${{paramName}} = $this->deserialize(${{paramName}}, '{{{dataType}}}', $inputFormat); - {{/bodyParams}} - {{^bodyParams}} - ${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}array<{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{^collectionFormat}}csv{{/collectionFormat}}>{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', 'string'); - {{/bodyParams}} + {{#isBodyParam}} + ${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}{{#items}}array<{{datatype}}>{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', $inputFormat); + {{/isBodyParam}} + {{^isBodyParam}} + ${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}array<{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{^collectionFormat}}csv{{/collectionFormat}},{{dataType}}>{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', 'string'); + {{/isBodyParam}} {{/isFile}} {{/allParams}} diff --git a/modules/swagger-codegen/src/main/resources/php-symfony/api_input_validation.mustache b/modules/swagger-codegen/src/main/resources/php-symfony/api_input_validation.mustache index 0bcd3053485..99792587651 100644 --- a/modules/swagger-codegen/src/main/resources/php-symfony/api_input_validation.mustache +++ b/modules/swagger-codegen/src/main/resources/php-symfony/api_input_validation.mustache @@ -16,11 +16,11 @@ {{/isContainer}} {{/isEnum}} {{#isContainer}} - $asserts[] = new Assert\All([ {{#items}} + $asserts[] = new Assert\All([ new Assert\Type("{{datatype}}") - {{/items}} ]); + {{/items}} {{/isContainer}} {{^isContainer}} {{#isDate}} diff --git a/modules/swagger-codegen/src/main/resources/php-symfony/model_generic.mustache b/modules/swagger-codegen/src/main/resources/php-symfony/model_generic.mustache index 8106055c854..15dd3594fa7 100644 --- a/modules/swagger-codegen/src/main/resources/php-symfony/model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/php-symfony/model_generic.mustache @@ -21,7 +21,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} /** * Gets {{name}}. * - * @return {{{datatype}}}{{^required}}|null{{/required}} + * @return {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}} */ public function {{getter}}() { @@ -31,7 +31,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} /** * Sets {{name}}. * - * @param {{{datatype}}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{description}}}{{/description}} + * @param {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{description}}}{{/description}} * * @return $this */ diff --git a/modules/swagger-codegen/src/main/resources/php-symfony/model_variables.mustache b/modules/swagger-codegen/src/main/resources/php-symfony/model_variables.mustache index d0af5b8579e..d05831defa3 100644 --- a/modules/swagger-codegen/src/main/resources/php-symfony/model_variables.mustache +++ b/modules/swagger-codegen/src/main/resources/php-symfony/model_variables.mustache @@ -3,7 +3,7 @@ * {{description}} * {{/description}} - * @var {{{datatype}}}{{^required}}|null{{/required}} + * @var {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}} * @SerializedName("{{baseName}}") {{#required}} * @Assert\NotNull() diff --git a/modules/swagger-codegen/src/main/resources/php-symfony/serialization/JmsSerializer.mustache b/modules/swagger-codegen/src/main/resources/php-symfony/serialization/JmsSerializer.mustache index 995e71ba023..e4e7c96499b 100644 --- a/modules/swagger-codegen/src/main/resources/php-symfony/serialization/JmsSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php-symfony/serialization/JmsSerializer.mustache @@ -5,7 +5,6 @@ namespace {{servicePackage}}; use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; -use Swagger\Server\Service\StrictJsonDeserializationVisitor; use JMS\Serializer\XmlDeserializationVisitor; class JmsSerializer implements SerializerInterface @@ -50,6 +49,11 @@ class JmsSerializer implements SerializerInterface private function deserializeString($data, $type) { + // Figure out if we have an array format + if (1 === preg_match('/array<(csv|ssv|tsv|pipes),(int|string)>/i', $type, $matches)) { + return $this->deserializeArrayString($matches[1], $matches[2], $data); + } + switch ($type) { case 'int': case 'integer': @@ -75,17 +79,37 @@ class JmsSerializer implements SerializerInterface } break; - case 'array': - return explode(',', $data); - case 'array': - return explode(' ', $data); - case 'array': - return explode("\t", $data); - case 'array': - return explode('|', $data); } // If we end up here, just return data return $data; } + + private function deserializeArrayString($format, $type, $data) + { + // Parse the string using the correct separator + switch ($format) { + case 'csv': + $data = explode(',', $data); + break; + case 'ssv': + $data = explode(' ', $data); + break; + case 'tsv': + $data = explode("\t", $data); + break; + case 'pipes': + $data = explode('|', $data); + break; + default; + $data = []; + } + + // Deserialize each of the array elements + foreach ($data as $key => $item) { + $data[$key] = $this->deserializeString($item, $type); + } + + return $data; + } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php index 587f6d813a3..6693847a603 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -70,6 +70,8 @@ public function setapi_key($value); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function addPet(Pet $body, &$responseCode, array &$responseHeaders); @@ -83,6 +85,8 @@ public function addPet(Pet $body, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders); @@ -123,7 +127,7 @@ public function findPetsByTags(array $tags, &$responseCode, array &$responseHead * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return Swagger\Server\Model\Pet + * @return Swagger\Server\Model\Pet[] * */ public function getPetById($petId, &$responseCode, array &$responseHeaders); @@ -137,6 +141,8 @@ public function getPetById($petId, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function updatePet(Pet $body, &$responseCode, array &$responseHeaders); @@ -151,6 +157,8 @@ public function updatePet(Pet $body, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders); @@ -165,7 +173,7 @@ public function updatePetWithForm($petId, $name = null, $status = null, &$respon * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return Swagger\Server\Model\ApiResponse + * @return Swagger\Server\Model\ApiResponse[] * */ public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php index 970531a6ded..bd2d95e8e0b 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php @@ -60,6 +60,8 @@ public function setapi_key($value); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function deleteOrder($orderId, &$responseCode, array &$responseHeaders); @@ -71,7 +73,7 @@ public function deleteOrder($orderId, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return int[] + * @return int * */ public function getInventory(&$responseCode, array &$responseHeaders); @@ -85,7 +87,7 @@ public function getInventory(&$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return Swagger\Server\Model\Order + * @return Swagger\Server\Model\Order[] * */ public function getOrderById($orderId, &$responseCode, array &$responseHeaders); @@ -99,7 +101,7 @@ public function getOrderById($orderId, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return Swagger\Server\Model\Order + * @return Swagger\Server\Model\Order[] * */ public function placeOrder(Order $body, &$responseCode, array &$responseHeaders); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php index e563cb71560..0dcd1045f80 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php @@ -51,6 +51,8 @@ interface UserApiInterface * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function createUser(User $body, &$responseCode, array &$responseHeaders); @@ -63,6 +65,8 @@ public function createUser(User $body, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function createUsersWithArrayInput(array $body, &$responseCode, array &$responseHeaders); @@ -75,6 +79,8 @@ public function createUsersWithArrayInput(array $body, &$responseCode, array &$r * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function createUsersWithListInput(array $body, &$responseCode, array &$responseHeaders); @@ -87,6 +93,8 @@ public function createUsersWithListInput(array $body, &$responseCode, array &$re * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function deleteUser($username, &$responseCode, array &$responseHeaders); @@ -99,7 +107,7 @@ public function deleteUser($username, &$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return Swagger\Server\Model\User + * @return Swagger\Server\Model\User[] * */ public function getUserByName($username, &$responseCode, array &$responseHeaders); @@ -127,6 +135,8 @@ public function loginUser($username, $password, &$responseCode, array &$response * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function logoutUser(&$responseCode, array &$responseHeaders); @@ -140,6 +150,8 @@ public function logoutUser(&$responseCode, array &$responseHeaders); * @param integer $responseCode The HTTP response code to return * @param array $responseHeaders Additional HTTP headers to return with the response () * + * @return void + * */ public function updateUser($username, User $body, &$responseCode, array &$responseHeaders); } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php index 9362b82b123..d665024f0e3 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php @@ -87,7 +87,6 @@ public function addPetAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - $body = $this->deserialize($body, 'Swagger\Server\Model\Pet', $inputFormat); // Validate the input values @@ -162,17 +161,12 @@ public function deletePetAction(Request $request, $petId) $securitypetstore_auth = $request->headers->get('authorization'); // Read out all input parameter values into variables - $apiKey = $request->headers->get('apiKey'); + $apiKey = $request->headers->get('api_key'); // Use the default value if no value was provided // Deserialize the input values that needs it $petId = $this->deserialize($petId, 'int', 'string'); - $apiKey = $request->headers->get('apiKey'); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it $apiKey = $this->deserialize($apiKey, 'string', 'string'); // Validate the input values @@ -258,7 +252,7 @@ public function findPetsByStatusAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - $status = $this->deserialize($status, 'array', 'string'); + $status = $this->deserialize($status, 'array', 'string'); // Validate the input values $asserts = []; @@ -345,7 +339,7 @@ public function findPetsByTagsAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - $tags = $this->deserialize($tags, 'array', 'string'); + $tags = $this->deserialize($tags, 'array', 'string'); // Validate the input values $asserts = []; @@ -521,7 +515,6 @@ public function updatePetAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - $body = $this->deserialize($body, 'Swagger\Server\Model\Pet', $inputFormat); // Validate the input values @@ -609,19 +602,7 @@ public function updatePetWithFormAction(Request $request, $petId) // Deserialize the input values that needs it $petId = $this->deserialize($petId, 'int', 'string'); - $name = $request->request->get('name'); - $status = $request->request->get('status'); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it $name = $this->deserialize($name, 'string', 'string'); - $name = $request->request->get('name'); - $status = $request->request->get('status'); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it $status = $this->deserialize($status, 'string', 'string'); // Validate the input values @@ -715,19 +696,7 @@ public function uploadFileAction(Request $request, $petId) // Deserialize the input values that needs it $petId = $this->deserialize($petId, 'int', 'string'); - $additionalMetadata = $request->request->get('additionalMetadata'); - $file = $request->files->get('file'); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it $additionalMetadata = $this->deserialize($additionalMetadata, 'string', 'string'); - $additionalMetadata = $request->request->get('additionalMetadata'); - $file = $request->files->get('file'); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it // Validate the input values $asserts = []; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php index 304a847c6eb..7402973dc2e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php @@ -150,6 +150,10 @@ public function getInventoryAction(Request $request) // Read out all input parameter values into variables + // Use the default value if no value was provided + + // Deserialize the input values that needs it + // Validate the input values @@ -306,7 +310,6 @@ public function placeOrderAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - $body = $this->deserialize($body, 'Swagger\Server\Model\Order', $inputFormat); // Validate the input values diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php index 7f182bb1e61..37d3c9796b0 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php @@ -83,7 +83,6 @@ public function createUserAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - $body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat); // Validate the input values @@ -166,14 +165,13 @@ public function createUsersWithArrayInputAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - - $body = $this->deserialize($body, 'Swagger\Server\Model\User[]', $inputFormat); + $body = $this->deserialize($body, 'array', $inputFormat); // Validate the input values $asserts = []; $asserts[] = new Assert\NotNull(); $asserts[] = new Assert\All([ - new Assert\Type("Swagger\Server\Model\User[]") + new Assert\Type("Swagger\Server\Model\User") ]); $response = $this->validate($body, $asserts); if ($response instanceof Response) { @@ -251,14 +249,13 @@ public function createUsersWithListInputAction(Request $request) // Use the default value if no value was provided // Deserialize the input values that needs it - - $body = $this->deserialize($body, 'Swagger\Server\Model\User[]', $inputFormat); + $body = $this->deserialize($body, 'array', $inputFormat); // Validate the input values $asserts = []; $asserts[] = new Assert\NotNull(); $asserts[] = new Assert\All([ - new Assert\Type("Swagger\Server\Model\User[]") + new Assert\Type("Swagger\Server\Model\User") ]); $response = $this->validate($body, $asserts); if ($response instanceof Response) { @@ -485,12 +482,6 @@ public function loginUserAction(Request $request) // Deserialize the input values that needs it $username = $this->deserialize($username, 'string', 'string'); - $username = $request->query->get('username'); - $password = $request->query->get('password'); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it $password = $this->deserialize($password, 'string', 'string'); // Validate the input values @@ -571,6 +562,10 @@ public function logoutUserAction(Request $request) // Read out all input parameter values into variables + // Use the default value if no value was provided + + // Deserialize the input values that needs it + // Validate the input values @@ -644,14 +639,7 @@ public function updateUserAction(Request $request, $username) // Use the default value if no value was provided // Deserialize the input values that needs it - - $body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat); - $body = $request->getContent(); - - // Use the default value if no value was provided - - // Deserialize the input values that needs it - + $username = $this->deserialize($username, 'string', 'string'); $body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat); // Validate the input values diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index ac3fba47a7d..184bead21b2 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -203,7 +203,7 @@ public function getPhotoUrls() * * @return $this */ - public function setPhotoUrls(array $photoUrls) + public function setPhotoUrls($photoUrls) { $this->photoUrls = $photoUrls; @@ -227,7 +227,7 @@ public function getTags() * * @return $this */ - public function setTags(array $tags = null) + public function setTags(Tag $tags = null) { $this->tags = $tags; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md index fba60fbaee3..7136065d3c7 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md @@ -152,7 +152,7 @@ void (empty response body) [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) ## **findPetsByStatus** -> Swagger\Server\Model\Pet[] findPetsByStatus($status) +> Swagger\Server\Model\Pet findPetsByStatus($status) Finds Pets by status @@ -196,11 +196,11 @@ class PetApi implements PetApiInterface Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**string[]**](../Model/string.md)| Status values that need to be considered for filter | + **status** | [**string**](../Model/string.md)| Status values that need to be considered for filter | ### Return type -[**Swagger\Server\Model\Pet[]**](../Model/Pet.md) +[**Swagger\Server\Model\Pet**](../Model/Pet.md) ### Authorization @@ -214,7 +214,7 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) ## **findPetsByTags** -> Swagger\Server\Model\Pet[] findPetsByTags($tags) +> Swagger\Server\Model\Pet findPetsByTags($tags) Finds Pets by tags @@ -258,11 +258,11 @@ class PetApi implements PetApiInterface Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**string[]**](../Model/string.md)| Tags to filter by | + **tags** | [**string**](../Model/string.md)| Tags to filter by | ### Return type -[**Swagger\Server\Model\Pet[]**](../Model/Pet.md) +[**Swagger\Server\Model\Pet**](../Model/Pet.md) ### Authorization diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md index 6cf48e1cd69..b174edf2686 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md @@ -77,7 +77,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) ## **getInventory** -> int[] getInventory() +> int getInventory() Returns pet inventories by status @@ -122,7 +122,7 @@ This endpoint does not need any parameter. ### Return type -**int[]** +**int** ### Authorization diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md index abb9582c545..3ba88c5059d 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md @@ -117,7 +117,7 @@ class UserApi implements UserApiInterface Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**Swagger\Server\Model\User[]**](../Model/User.md)| List of user object | + **body** | [**Swagger\Server\Model\User**](../Model/User.md)| List of user object | ### Return type @@ -171,7 +171,7 @@ class UserApi implements UserApiInterface Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**Swagger\Server\Model\User[]**](../Model/User.md)| List of user object | + **body** | [**Swagger\Server\Model\User**](../Model/User.md)| List of user object | ### Return type diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md index c10f63dc79c..96378811aad 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Model/Pet.md @@ -6,8 +6,8 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **category** | [**Swagger\Server\Model\Category**](Category.md) | | [optional] **name** | **string** | | -**photoUrls** | **string[]** | | -**tags** | [**Swagger\Server\Model\Tag[]**](Tag.md) | | [optional] +**photoUrls** | **string** | | +**tags** | [**Swagger\Server\Model\Tag**](Tag.md) | | [optional] **status** | **string** | pet status in the store | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 7b0fce321a6..d9b59280dd6 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php @@ -5,7 +5,6 @@ use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; -use Swagger\Server\Service\StrictJsonDeserializationVisitor; use JMS\Serializer\XmlDeserializationVisitor; class JmsSerializer implements SerializerInterface @@ -50,6 +49,11 @@ private function convertFormat($format) private function deserializeString($data, $type) { + // Figure out if we have an array format + if (1 === preg_match('/array<(csv|ssv|tsv|pipes),(int|string)>/i', $type, $matches)) { + return $this->deserializeArrayString($matches[1], $matches[2], $data); + } + switch ($type) { case 'int': case 'integer': @@ -75,17 +79,37 @@ private function deserializeString($data, $type) } break; - case 'array': - return explode(',', $data); - case 'array': - return explode(' ', $data); - case 'array': - return explode("\t", $data); - case 'array': - return explode('|', $data); } // If we end up here, just return data return $data; } + + private function deserializeArrayString($format, $type, $data) + { + // Parse the string using the correct separator + switch ($format) { + case 'csv': + $data = explode(',', $data); + break; + case 'ssv': + $data = explode(' ', $data); + break; + case 'tsv': + $data = explode("\t", $data); + break; + case 'pipes': + $data = explode('|', $data); + break; + default; + $data = []; + } + + // Deserialize each of the array elements + foreach ($data as $key => $item) { + $data[$key] = $this->deserializeString($item, $type); + } + + return $data; + } }