Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -346,6 +346,16 @@ public Map<String, Object> postProcessOperations(Map<String, Object> 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
Expand All @@ -355,16 +365,14 @@ public Map<String, Object> postProcessOperations(Map<String, Object> 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
Expand Down Expand Up @@ -396,6 +404,12 @@ public Map<String, Object> postProcessModels(Map<String, Object> 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");
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}()
{
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* {{description}}
*
{{/description}}
* @var {{{datatype}}}{{^required}}|null{{/required}}
* @var {{{vendorExtensions.x-commentType}}}{{^required}}|null{{/required}}
* @SerializedName("{{baseName}}")
{{#required}}
* @Assert\NotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand All @@ -75,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Loading