[PHP][Symfony] Further enhancements (#7001)

* Further enchancements for PHP-Symfony. Fixes issues described in #6999

* Ran shell script to update petstore sample
This commit is contained in:
naelrashdeen
2017-11-27 09:25:50 +01:00
committed by William Cheng
parent a565a94a06
commit 5d59dd10ec
19 changed files with 165 additions and 122 deletions

View File

@@ -140,7 +140,7 @@ public class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
typeMapping.put("map", "array"); typeMapping.put("map", "array");
typeMapping.put("array", "array"); typeMapping.put("array", "array");
typeMapping.put("list", "array"); typeMapping.put("list", "array");
typeMapping.put("object", "object"); typeMapping.put("object", "array");
typeMapping.put("binary", "string"); typeMapping.put("binary", "string");
typeMapping.put("ByteArray", "string"); typeMapping.put("ByteArray", "string");
typeMapping.put("UUID", "string"); typeMapping.put("UUID", "string");
@@ -346,6 +346,16 @@ public class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
param.vendorExtensions.put("x-parameterType", typeHint); 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 // Quote default values for strings
// @todo: The default values for headers, forms and query params are handled // @todo: The default values for headers, forms and query params are handled
// in DefaultCodegen fromParameter with no real possibility to override // in DefaultCodegen fromParameter with no real possibility to override
@@ -355,16 +365,14 @@ public class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
} }
} }
for (CodegenResponse response : op.responses) { // Create a variable to display the correct return type in comments for interfaces
final String exception = SYMFONY_EXCEPTIONS.get(response.code); if (op.returnType != null) {
response.vendorExtensions.put("x-symfonyException", exception); op.vendorExtensions.put("x-commentType", op.returnType);
response.vendorExtensions.put("x-symfonyExceptionSimple", extractSimpleName(exception)); if (!op.returnTypeIsPrimitive) {
op.vendorExtensions.put("x-commentType", op.returnType+"[]");
// Add simple return type to response
if (response.dataType != null) {
final String dataType = extractSimpleName(response.dataType);
response.vendorExtensions.put("x-simpleName", dataType);
} }
} else {
op.vendorExtensions.put("x-commentType", "void");
} }
// Add operation's authentication methods to whole interface // Add operation's authentication methods to whole interface
@@ -396,6 +404,12 @@ public class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
var.vendorExtensions.put("x-parameterType", typeHint); 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) { if (var.isBoolean) {
var.getter = var.getter.replaceAll("^get", "is"); var.getter = var.getter.replaceAll("^get", "is");
} }
@@ -448,13 +462,13 @@ public class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
if (p instanceof ArrayProperty) { if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p; ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems(); Property inner = ap.getItems();
return getTypeDeclaration(inner) + "[]"; return getTypeDeclaration(inner);
} }
if (p instanceof MapProperty) { if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p; MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties(); Property inner = mp.getAdditionalProperties();
return getTypeDeclaration(inner) + "[]"; return getTypeDeclaration(inner);
} }
if (p instanceof RefProperty) { if (p instanceof RefProperty) {

View File

@@ -57,15 +57,13 @@ interface {{classname}}
* *
{{/description}} {{/description}}
{{#allParams}} {{#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}} {{/allParams}}
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
{{#returnType}} * @return {{{vendorExtensions.x-commentType}}}
* @return {{{returnType}}}
* *
{{/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); 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}} {{/operation}}

View File

@@ -99,12 +99,11 @@ class {{controllerName}} extends Controller
{{/authMethods}} {{/authMethods}}
// Read out all input parameter values into variables // Read out all input parameter values into variables
{{#allParams}}
{{#queryParams}} {{#queryParams}}
${{paramName}} = $request->query->get('{{paramName}}'); ${{paramName}} = $request->query->get('{{paramName}}');
{{/queryParams}} {{/queryParams}}
{{#headerParams}} {{#headerParams}}
${{paramName}} = $request->headers->get('{{paramName}}'); ${{paramName}} = $request->headers->get('{{baseName}}');
{{/headerParams}} {{/headerParams}}
{{#formParams}} {{#formParams}}
{{#isFile}} {{#isFile}}
@@ -135,14 +134,14 @@ class {{controllerName}} extends Controller
{{/required}} {{/required}}
// Deserialize the input values that needs it // Deserialize the input values that needs it
{{#allParams}}
{{^isFile}} {{^isFile}}
{{#bodyParams}} {{#isBodyParam}}
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}{{#items}}array<{{datatype}}>{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', $inputFormat);
${{paramName}} = $this->deserialize(${{paramName}}, '{{{dataType}}}', $inputFormat); {{/isBodyParam}}
{{/bodyParams}} {{^isBodyParam}}
{{^bodyParams}} ${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}array<{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{^collectionFormat}}csv{{/collectionFormat}},{{dataType}}>{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', 'string');
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}array<{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{^collectionFormat}}csv{{/collectionFormat}}>{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', 'string'); {{/isBodyParam}}
{{/bodyParams}}
{{/isFile}} {{/isFile}}
{{/allParams}} {{/allParams}}

View File

@@ -16,11 +16,11 @@
{{/isContainer}} {{/isContainer}}
{{/isEnum}} {{/isEnum}}
{{#isContainer}} {{#isContainer}}
$asserts[] = new Assert\All([
{{#items}} {{#items}}
$asserts[] = new Assert\All([
new Assert\Type("{{datatype}}") new Assert\Type("{{datatype}}")
{{/items}}
]); ]);
{{/items}}
{{/isContainer}} {{/isContainer}}
{{^isContainer}} {{^isContainer}}
{{#isDate}} {{#isDate}}

View File

@@ -21,7 +21,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}
/** /**
* Gets {{name}}. * Gets {{name}}.
* *
* @return {{{datatype}}}{{^required}}|null{{/required}} * @return {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}}
*/ */
public function {{getter}}() public function {{getter}}()
{ {
@@ -31,7 +31,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}
/** /**
* Sets {{name}}. * Sets {{name}}.
* *
* @param {{{datatype}}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{description}}}{{/description}} * @param {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{description}}}{{/description}}
* *
* @return $this * @return $this
*/ */

View File

@@ -3,7 +3,7 @@
* {{description}} * {{description}}
* *
{{/description}} {{/description}}
* @var {{{datatype}}}{{^required}}|null{{/required}} * @var {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}}
* @SerializedName("{{baseName}}") * @SerializedName("{{baseName}}")
{{#required}} {{#required}}
* @Assert\NotNull() * @Assert\NotNull()

View File

@@ -49,6 +49,11 @@ class JmsSerializer implements SerializerInterface
private function deserializeString($data, $type) 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) { switch ($type) {
case 'int': case 'int':
case 'integer': case 'integer':
@@ -74,17 +79,37 @@ class JmsSerializer implements SerializerInterface
} }
break; break;
case 'array<csv>':
return explode(',', $data);
case 'array<ssv>':
return explode(' ', $data);
case 'array<tsv>':
return explode("\t", $data);
case 'array<pipes>':
return explode('|', $data);
} }
// If we end up here, just return data // If we end up here, just return data
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;
}
} }

View File

@@ -70,6 +70,8 @@ interface PetApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function addPet(Pet $body, &$responseCode, array &$responseHeaders); public function addPet(Pet $body, &$responseCode, array &$responseHeaders);
@@ -83,6 +85,8 @@ interface PetApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders); public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders);
@@ -123,7 +127,7 @@ interface PetApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @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); public function getPetById($petId, &$responseCode, array &$responseHeaders);
@@ -137,6 +141,8 @@ interface PetApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function updatePet(Pet $body, &$responseCode, array &$responseHeaders); public function updatePet(Pet $body, &$responseCode, array &$responseHeaders);
@@ -151,6 +157,8 @@ interface PetApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders); public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders);
@@ -165,7 +173,7 @@ interface PetApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @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); public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders);

View File

@@ -60,6 +60,8 @@ interface StoreApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function deleteOrder($orderId, &$responseCode, array &$responseHeaders); public function deleteOrder($orderId, &$responseCode, array &$responseHeaders);
@@ -71,7 +73,7 @@ interface StoreApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return int[] * @return int
* *
*/ */
public function getInventory(&$responseCode, array &$responseHeaders); public function getInventory(&$responseCode, array &$responseHeaders);
@@ -85,7 +87,7 @@ interface StoreApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @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); public function getOrderById($orderId, &$responseCode, array &$responseHeaders);
@@ -99,7 +101,7 @@ interface StoreApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @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); public function placeOrder(Order $body, &$responseCode, array &$responseHeaders);

View File

@@ -51,6 +51,8 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function createUser(User $body, &$responseCode, array &$responseHeaders); public function createUser(User $body, &$responseCode, array &$responseHeaders);
@@ -63,6 +65,8 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function createUsersWithArrayInput(array $body, &$responseCode, array &$responseHeaders); public function createUsersWithArrayInput(array $body, &$responseCode, array &$responseHeaders);
@@ -75,6 +79,8 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function createUsersWithListInput(array $body, &$responseCode, array &$responseHeaders); public function createUsersWithListInput(array $body, &$responseCode, array &$responseHeaders);
@@ -87,6 +93,8 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function deleteUser($username, &$responseCode, array &$responseHeaders); public function deleteUser($username, &$responseCode, array &$responseHeaders);
@@ -99,7 +107,7 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @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); public function getUserByName($username, &$responseCode, array &$responseHeaders);
@@ -127,6 +135,8 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function logoutUser(&$responseCode, array &$responseHeaders); public function logoutUser(&$responseCode, array &$responseHeaders);
@@ -140,6 +150,8 @@ interface UserApiInterface
* @param integer $responseCode The HTTP response code to return * @param integer $responseCode The HTTP response code to return
* @param array $responseHeaders Additional HTTP headers to return with the response () * @param array $responseHeaders Additional HTTP headers to return with the response ()
* *
* @return void
*
*/ */
public function updateUser($username, User $body, &$responseCode, array &$responseHeaders); public function updateUser($username, User $body, &$responseCode, array &$responseHeaders);
} }

View File

@@ -87,7 +87,6 @@ class PetController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$body = $this->deserialize($body, 'Swagger\Server\Model\Pet', $inputFormat); $body = $this->deserialize($body, 'Swagger\Server\Model\Pet', $inputFormat);
// Validate the input values // Validate the input values
@@ -162,17 +161,12 @@ class PetController extends Controller
$securitypetstore_auth = $request->headers->get('authorization'); $securitypetstore_auth = $request->headers->get('authorization');
// Read out all input parameter values into variables // 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 // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string'); $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'); $apiKey = $this->deserialize($apiKey, 'string', 'string');
// Validate the input values // Validate the input values
@@ -258,7 +252,7 @@ class PetController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$status = $this->deserialize($status, 'array<csv>', 'string'); $status = $this->deserialize($status, 'array<csv,string>', 'string');
// Validate the input values // Validate the input values
$asserts = []; $asserts = [];
@@ -345,7 +339,7 @@ class PetController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$tags = $this->deserialize($tags, 'array<csv>', 'string'); $tags = $this->deserialize($tags, 'array<csv,string>', 'string');
// Validate the input values // Validate the input values
$asserts = []; $asserts = [];
@@ -521,7 +515,6 @@ class PetController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$body = $this->deserialize($body, 'Swagger\Server\Model\Pet', $inputFormat); $body = $this->deserialize($body, 'Swagger\Server\Model\Pet', $inputFormat);
// Validate the input values // Validate the input values
@@ -609,19 +602,7 @@ class PetController extends Controller
// Deserialize the input values that needs it // Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string'); $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 = $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'); $status = $this->deserialize($status, 'string', 'string');
// Validate the input values // Validate the input values
@@ -715,19 +696,7 @@ class PetController extends Controller
// Deserialize the input values that needs it // Deserialize the input values that needs it
$petId = $this->deserialize($petId, 'int', 'string'); $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 = $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 // Validate the input values
$asserts = []; $asserts = [];

View File

@@ -150,6 +150,10 @@ class StoreController extends Controller
// Read out all input parameter values into variables // 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 // Validate the input values
@@ -306,7 +310,6 @@ class StoreController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$body = $this->deserialize($body, 'Swagger\Server\Model\Order', $inputFormat); $body = $this->deserialize($body, 'Swagger\Server\Model\Order', $inputFormat);
// Validate the input values // Validate the input values

View File

@@ -83,7 +83,6 @@ class UserController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat); $body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat);
// Validate the input values // Validate the input values
@@ -166,14 +165,13 @@ class UserController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$body = $this->deserialize($body, 'array<Swagger\Server\Model\User>', $inputFormat);
$body = $this->deserialize($body, 'Swagger\Server\Model\User[]', $inputFormat);
// Validate the input values // Validate the input values
$asserts = []; $asserts = [];
$asserts[] = new Assert\NotNull(); $asserts[] = new Assert\NotNull();
$asserts[] = new Assert\All([ $asserts[] = new Assert\All([
new Assert\Type("Swagger\Server\Model\User[]") new Assert\Type("Swagger\Server\Model\User")
]); ]);
$response = $this->validate($body, $asserts); $response = $this->validate($body, $asserts);
if ($response instanceof Response) { if ($response instanceof Response) {
@@ -251,14 +249,13 @@ class UserController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$body = $this->deserialize($body, 'array<Swagger\Server\Model\User>', $inputFormat);
$body = $this->deserialize($body, 'Swagger\Server\Model\User[]', $inputFormat);
// Validate the input values // Validate the input values
$asserts = []; $asserts = [];
$asserts[] = new Assert\NotNull(); $asserts[] = new Assert\NotNull();
$asserts[] = new Assert\All([ $asserts[] = new Assert\All([
new Assert\Type("Swagger\Server\Model\User[]") new Assert\Type("Swagger\Server\Model\User")
]); ]);
$response = $this->validate($body, $asserts); $response = $this->validate($body, $asserts);
if ($response instanceof Response) { if ($response instanceof Response) {
@@ -485,12 +482,6 @@ class UserController extends Controller
// Deserialize the input values that needs it // Deserialize the input values that needs it
$username = $this->deserialize($username, 'string', 'string'); $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'); $password = $this->deserialize($password, 'string', 'string');
// Validate the input values // Validate the input values
@@ -571,6 +562,10 @@ class UserController extends Controller
// Read out all input parameter values into variables // 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 // Validate the input values
@@ -644,14 +639,7 @@ class UserController extends Controller
// Use the default value if no value was provided // Use the default value if no value was provided
// Deserialize the input values that needs it // Deserialize the input values that needs it
$username = $this->deserialize($username, 'string', 'string');
$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
$body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat); $body = $this->deserialize($body, 'Swagger\Server\Model\User', $inputFormat);
// Validate the input values // Validate the input values

View File

@@ -203,7 +203,7 @@ class Pet
* *
* @return $this * @return $this
*/ */
public function setPhotoUrls(array $photoUrls) public function setPhotoUrls($photoUrls)
{ {
$this->photoUrls = $photoUrls; $this->photoUrls = $photoUrls;
@@ -227,7 +227,7 @@ class Pet
* *
* @return $this * @return $this
*/ */
public function setTags(array $tags = null) public function setTags(Tag $tags = null)
{ {
$this->tags = $tags; $this->tags = $tags;

View File

@@ -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) [[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** ## **findPetsByStatus**
> Swagger\Server\Model\Pet[] findPetsByStatus($status) > Swagger\Server\Model\Pet findPetsByStatus($status)
Finds Pets by status Finds Pets by status
@@ -196,11 +196,11 @@ class PetApi implements PetApiInterface
Name | Type | Description | Notes 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 ### Return type
[**Swagger\Server\Model\Pet[]**](../Model/Pet.md) [**Swagger\Server\Model\Pet**](../Model/Pet.md)
### Authorization ### 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) [[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** ## **findPetsByTags**
> Swagger\Server\Model\Pet[] findPetsByTags($tags) > Swagger\Server\Model\Pet findPetsByTags($tags)
Finds Pets by tags Finds Pets by tags
@@ -258,11 +258,11 @@ class PetApi implements PetApiInterface
Name | Type | Description | Notes Name | Type | Description | Notes
------------- | ------------- | ------------- | ------------- ------------- | ------------- | ------------- | -------------
**tags** | [**string[]**](../Model/string.md)| Tags to filter by | **tags** | [**string**](../Model/string.md)| Tags to filter by |
### Return type ### Return type
[**Swagger\Server\Model\Pet[]**](../Model/Pet.md) [**Swagger\Server\Model\Pet**](../Model/Pet.md)
### Authorization ### Authorization

View File

@@ -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) [[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** ## **getInventory**
> int[] getInventory() > int getInventory()
Returns pet inventories by status Returns pet inventories by status
@@ -122,7 +122,7 @@ This endpoint does not need any parameter.
### Return type ### Return type
**int[]** **int**
### Authorization ### Authorization

View File

@@ -117,7 +117,7 @@ class UserApi implements UserApiInterface
Name | Type | Description | Notes 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 ### Return type
@@ -171,7 +171,7 @@ class UserApi implements UserApiInterface
Name | Type | Description | Notes 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 ### Return type

View File

@@ -6,8 +6,8 @@ Name | Type | Description | Notes
**id** | **int** | | [optional] **id** | **int** | | [optional]
**category** | [**Swagger\Server\Model\Category**](Category.md) | | [optional] **category** | [**Swagger\Server\Model\Category**](Category.md) | | [optional]
**name** | **string** | | **name** | **string** | |
**photoUrls** | **string[]** | | **photoUrls** | **string** | |
**tags** | [**Swagger\Server\Model\Tag[]**](Tag.md) | | [optional] **tags** | [**Swagger\Server\Model\Tag**](Tag.md) | | [optional]
**status** | **string** | pet status in the store | [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) [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -49,6 +49,11 @@ class JmsSerializer implements SerializerInterface
private function deserializeString($data, $type) 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) { switch ($type) {
case 'int': case 'int':
case 'integer': case 'integer':
@@ -74,17 +79,37 @@ class JmsSerializer implements SerializerInterface
} }
break; break;
case 'array<csv>':
return explode(',', $data);
case 'array<ssv>':
return explode(' ', $data);
case 'array<tsv>':
return explode("\t", $data);
case 'array<pipes>':
return explode('|', $data);
} }
// If we end up here, just return data // If we end up here, just return data
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;
}
} }