Skip to content

Commit bb18191

Browse files
committed
[php Symfony] fix return type for non json/xml api
This fixes the generated returned type of controller methods for endpoint with a response declared like content: text/plain: schema: type: <boolean|string|integer|number> or for content: image/png: schema: type: string format: binary Without this commit the generated method *had to* return a value that matched "array|object|null", which does not work in this case. This commit makes it possible to return the proper type.
1 parent d300ae9 commit bb18191

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,17 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
417417
op.vendorExtensions.put("x-comment-type", "void");
418418
}
419419
// Create a variable to add typing for return value of interface
420-
if (op.returnType != null) {
420+
if ("bool".equals(op.returnType)) {
421+
op.vendorExtensions.put("x-return-type", "bool");
422+
} else if ("UploadedFile".equals(op.returnType)) {
423+
op.vendorExtensions.put("x-return-type", "string");
424+
} else if ("int".equals(op.returnType)) {
425+
op.vendorExtensions.put("x-return-type", "int");
426+
} else if ("float".equals(op.returnType)) {
427+
op.vendorExtensions.put("x-return-type", "float");
428+
} else if ("string".equals(op.returnType)) {
429+
op.vendorExtensions.put("x-return-type", "string");
430+
} else if (op.returnType != null) {
421431
op.vendorExtensions.put("x-return-type", "array|object|null");
422432
} else {
423433
op.vendorExtensions.put("x-return-type", "void");

samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ public function deleteOrder(
7777
* @param int &$responseCode The HTTP Response Code
7878
* @param array $responseHeaders Additional HTTP headers to return with the response ()
7979
*
80-
* @return array|object|null
80+
* @return int
8181
*/
8282
public function getInventory(
8383
int &$responseCode,
8484
array &$responseHeaders
85-
): array|object|null;
85+
): int;
8686

8787
/**
8888
* Operation getOrderById

samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ public function getUserByName(
147147
* @param int &$responseCode The HTTP Response Code
148148
* @param array $responseHeaders Additional HTTP headers to return with the response ()
149149
*
150-
* @return array|object|null
150+
* @return string
151151
*/
152152
public function loginUser(
153153
string $username,
154154
string $password,
155155
int &$responseCode,
156156
array &$responseHeaders
157-
): array|object|null;
157+
): string;
158158

159159
/**
160160
* Operation logoutUser

samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/StoreApiInterface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class StoreApi implements StoreApiInterface
107107
/**
108108
* Implementation of StoreApiInterface#getInventory
109109
*/
110-
public function getInventory(int &$responseCode, array &$responseHeaders): array|object|null
110+
public function getInventory(int &$responseCode, array &$responseHeaders): int
111111
{
112112
// Implement the operation ...
113113
}

samples/server/petstore/php-symfony/SymfonyBundle-php/docs/Api/UserApiInterface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class UserApi implements UserApiInterface
351351
/**
352352
* Implementation of UserApiInterface#loginUser
353353
*/
354-
public function loginUser(string $username, string $password, int &$responseCode, array &$responseHeaders): array|object|null
354+
public function loginUser(string $username, string $password, int &$responseCode, array &$responseHeaders): string
355355
{
356356
// Implement the operation ...
357357
}

0 commit comments

Comments
 (0)