forked from loafle/openapi-generator-original
[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:
committed by
William Cheng
parent
a565a94a06
commit
5d59dd10ec
@@ -140,7 +140,7 @@ public class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
|
||||
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 class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
|
||||
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 class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
|
||||
}
|
||||
}
|
||||
|
||||
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 class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
|
||||
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 class SymfonyServerCodegen extends AbstractPhpCodegen implements CodegenC
|
||||
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) {
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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}}
|
||||
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* {{description}}
|
||||
*
|
||||
{{/description}}
|
||||
* @var {{{datatype}}}{{^required}}|null{{/required}}
|
||||
* @var {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}}
|
||||
* @SerializedName("{{baseName}}")
|
||||
{{#required}}
|
||||
* @Assert\NotNull()
|
||||
|
||||
@@ -49,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':
|
||||
@@ -74,17 +79,37 @@ class JmsSerializer implements SerializerInterface
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ interface PetApiInterface
|
||||
* @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 @@ interface PetApiInterface
|
||||
* @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 @@ interface PetApiInterface
|
||||
* @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 @@ interface PetApiInterface
|
||||
* @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 @@ interface PetApiInterface
|
||||
* @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 @@ interface PetApiInterface
|
||||
* @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);
|
||||
|
||||
@@ -60,6 +60,8 @@ interface StoreApiInterface
|
||||
* @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 @@ interface StoreApiInterface
|
||||
* @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 @@ interface StoreApiInterface
|
||||
* @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 @@ interface StoreApiInterface
|
||||
* @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);
|
||||
|
||||
@@ -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 @@ 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 createUsersWithArrayInput(array $body, &$responseCode, array &$responseHeaders);
|
||||
|
||||
@@ -75,6 +79,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 createUsersWithListInput(array $body, &$responseCode, array &$responseHeaders);
|
||||
|
||||
@@ -87,6 +93,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 deleteUser($username, &$responseCode, array &$responseHeaders);
|
||||
|
||||
@@ -99,7 +107,7 @@ interface UserApiInterface
|
||||
* @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 @@ 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 logoutUser(&$responseCode, array &$responseHeaders);
|
||||
|
||||
@@ -140,6 +150,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 updateUser($username, User $body, &$responseCode, array &$responseHeaders);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,6 @@ class PetController extends Controller
|
||||
// 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 @@ class PetController extends Controller
|
||||
$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 @@ class PetController extends Controller
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// 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
|
||||
$asserts = [];
|
||||
@@ -345,7 +339,7 @@ class PetController extends Controller
|
||||
// Use the default value if no value was provided
|
||||
|
||||
// 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
|
||||
$asserts = [];
|
||||
@@ -521,7 +515,6 @@ class PetController extends Controller
|
||||
// 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 @@ class PetController extends Controller
|
||||
|
||||
// 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 @@ class PetController extends Controller
|
||||
|
||||
// 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 = [];
|
||||
|
||||
@@ -150,6 +150,10 @@ class StoreController extends Controller
|
||||
|
||||
// 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 @@ class StoreController extends Controller
|
||||
// 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
|
||||
|
||||
@@ -83,7 +83,6 @@ class UserController extends Controller
|
||||
// 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 @@ class UserController extends Controller
|
||||
// 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<Swagger\Server\Model\User>', $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 @@ class UserController extends Controller
|
||||
// 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<Swagger\Server\Model\User>', $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 @@ class UserController extends Controller
|
||||
|
||||
// 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 @@ class UserController extends Controller
|
||||
|
||||
// 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 @@ class UserController extends Controller
|
||||
// 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
|
||||
|
||||
@@ -203,7 +203,7 @@ class Pet
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPhotoUrls(array $photoUrls)
|
||||
public function setPhotoUrls($photoUrls)
|
||||
{
|
||||
$this->photoUrls = $photoUrls;
|
||||
|
||||
@@ -227,7 +227,7 @@ class Pet
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTags(array $tags = null)
|
||||
public function setTags(Tag $tags = null)
|
||||
{
|
||||
$this->tags = $tags;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -49,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':
|
||||
@@ -74,17 +79,37 @@ class JmsSerializer implements SerializerInterface
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user