diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpFlightServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpFlightServerCodegen.java index d6155803e0ee..f7248ac77a28 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpFlightServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpFlightServerCodegen.java @@ -34,6 +34,7 @@ import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.CodegenResponse; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; import org.openapitools.codegen.meta.GeneratorMetadata; @@ -202,11 +203,14 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List operationList = operations.getOperation(); operationList.forEach(operation -> { operation.vendorExtensions.put("x-path", mapToFlightPath(operation.path)); - String returnType = operation.responses.stream().filter(r -> r.is2xx && r.dataType != null).map(r -> this.getTypeHint(r.dataType, false, false)).filter(t -> !t.isEmpty()).map(t -> t + "|null").findFirst().orElse("void"); + CodegenResponse defaultResponse = operation.responses.stream().filter(r -> r.is2xx && r.dataType != null && !this.getTypeHint(r.dataType, false, false).isEmpty()).findFirst().orElse(null); + String returnType = defaultResponse != null ? this.getTypeHint(defaultResponse.dataType, false, false) + "|null" : "void"; operation.vendorExtensions.put("x-return-type", returnType); operation.vendorExtensions.put("x-return-type-is-void", returnType.equals("void")); - operation.vendorExtensions.put("x-return-type-comment", - operation.responses.stream().filter(r -> r.is2xx && r.dataType != null).map(r -> this.getTypeHint(r.dataType, true, false)).filter(t -> !t.isEmpty()).map(t -> t + "|null").findFirst().orElse("void")); + operation.vendorExtensions.put("x-return-type-comment", defaultResponse != null ? this.getTypeHint(defaultResponse.dataType, true, false) + "|null" : "void"); + operation.vendorExtensions.put("x-default-media-type", defaultResponse != null ? ( + defaultResponse.getContent().containsKey("application/json") ? "application/json" : defaultResponse.getContent().keySet().stream().findFirst().orElse(null)) : null); + operation.vendorExtensions.put("x-default-status-code", defaultResponse != null ? defaultResponse.code : operation.responses.stream().filter(r -> !r.isDefault).findFirst().map(r -> r.code).orElse("200")); operation.vendorExtensions.put("x-nonFormParams", operation.allParams.stream().filter(p -> !p.isFormParam).toArray()); operation.allParams.forEach(param -> { diff --git a/modules/openapi-generator/src/main/resources/php-flight/api.mustache b/modules/openapi-generator/src/main/resources/php-flight/api.mustache index a0b146bd07dc..9824f8f8697d 100644 --- a/modules/openapi-generator/src/main/resources/php-flight/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-flight/api.mustache @@ -11,7 +11,8 @@ namespace {{apiPackage}}; {{#operation}} /** * Operation {{{operationId}}} - * Path: {{{path}}} + * + * Path: `{{{path}}}` * {{#summary}} * {{{summary}}} @@ -31,10 +32,11 @@ namespace {{apiPackage}}; throw new \Exception('Not implemented'); } - {{#returnContainer}} /** * Operation {{{operationId}}} (stream) * + * Path: `{{{path}}}` + * {{#summary}} * {{{summary}}} * @@ -51,7 +53,6 @@ namespace {{apiPackage}}; { throw new \Exception('Not implemented'); } - {{/returnContainer}} {{/operation}} } {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/php-flight/register_routes.mustache b/modules/openapi-generator/src/main/resources/php-flight/register_routes.mustache index 42aebdee00a7..1056f6be4c8b 100644 --- a/modules/openapi-generator/src/main/resources/php-flight/register_routes.mustache +++ b/modules/openapi-generator/src/main/resources/php-flight/register_routes.mustache @@ -27,17 +27,16 @@ class RegisterRoutes { ); {{^vendorExtensions.x-return-type-is-void}} if ($result === null) { - \Flight::halt(204); + \Flight::halt({{{vendorExtensions.x-default-status-code}}}); } else { - \Flight::json($result); + \Flight::json($result, {{{vendorExtensions.x-default-status-code}}}); } {{/vendorExtensions.x-return-type-is-void}} {{#vendorExtensions.x-return-type-is-void}} - \Flight::halt(204); + \Flight::halt({{{vendorExtensions.x-default-status-code}}}); {{/vendorExtensions.x-return-type-is-void}} }); } - {{#returnContainer}} if (declaresMethod($reflectionClass, '{{operationId}}Stream')) { \Flight::route('{{httpMethod}} {{vendorExtensions.x-path}}', function ({{#pathParams}}string ${{paramName}}{{^-last}}, {{/-last}}{{/pathParams}}) use ($handler) { $r = \Flight::request(); @@ -47,9 +46,8 @@ class RegisterRoutes { {{/vendorExtensions.x-nonFormParams}} ); // ignore return value: streaming expected - })->streamWithHeaders(['Content-Type' => 'application/json']); + })->streamWithHeaders(['status' => {{{vendorExtensions.x-default-status-code}}}{{#vendorExtensions.x-default-media-type}}, 'Content-Type' => '{{{vendorExtensions.x-default-media-type}}}'{{/vendorExtensions.x-default-media-type}}]); } - {{/returnContainer}} {{/operation}} {{/operations}} diff --git a/samples/server/petstore/php-flight/Api/AbstractPetApi.php b/samples/server/petstore/php-flight/Api/AbstractPetApi.php index f895ed6e2734..949e7d1f2f1a 100644 --- a/samples/server/petstore/php-flight/Api/AbstractPetApi.php +++ b/samples/server/petstore/php-flight/Api/AbstractPetApi.php @@ -23,7 +23,8 @@ abstract class AbstractPetApi /** * Operation addPet - * Path: /pet + * + * Path: `/pet` * * Add a new pet to the store * @@ -36,9 +37,24 @@ public function addPet(\OpenAPIServer\Model\Pet $pet): \OpenAPIServer\Model\Pet| throw new \Exception('Not implemented'); } + /** + * Operation addPet (stream) + * + * Path: `/pet` + * + * Add a new pet to the store + * + * @param \OpenAPIServer\Model\Pet $pet Pet object that needs to be added to the store (required) + * + */ + public function addPetStream(\OpenAPIServer\Model\Pet $pet): void + { + throw new \Exception('Not implemented'); + } /** * Operation deletePet - * Path: /pet/{petId} + * + * Path: `/pet/{petId}` * * Deletes a pet * @@ -52,9 +68,25 @@ public function deletePet(int $petId, ?string $apiKey): void throw new \Exception('Not implemented'); } + /** + * Operation deletePet (stream) + * + * Path: `/pet/{petId}` + * + * Deletes a pet + * + * @param int $petId Pet id to delete (required) + * @param ?string $apiKey (optional) + * + */ + public function deletePetStream(int $petId, ?string $apiKey): void + { + throw new \Exception('Not implemented'); + } /** * Operation findPetsByStatus - * Path: /pet/findByStatus + * + * Path: `/pet/findByStatus` * * Finds Pets by status * @@ -70,6 +102,8 @@ public function findPetsByStatus(array $status): array|null /** * Operation findPetsByStatus (stream) * + * Path: `/pet/findByStatus` + * * Finds Pets by status * * @param array $status Status values that need to be considered for filter (required) (deprecated) @@ -81,7 +115,8 @@ public function findPetsByStatusStream(array $status): void } /** * Operation findPetsByTags - * Path: /pet/findByTags + * + * Path: `/pet/findByTags` * * Finds Pets by tags * @@ -98,6 +133,8 @@ public function findPetsByTags(array $tags): array|null /** * Operation findPetsByTags (stream) * + * Path: `/pet/findByTags` + * * Finds Pets by tags * * @param array $tags Tags to filter by (required) @@ -110,7 +147,8 @@ public function findPetsByTagsStream(array $tags): void } /** * Operation getPetById - * Path: /pet/{petId} + * + * Path: `/pet/{petId}` * * Find pet by ID * @@ -123,9 +161,24 @@ public function getPetById(int $petId): \OpenAPIServer\Model\Pet|null throw new \Exception('Not implemented'); } + /** + * Operation getPetById (stream) + * + * Path: `/pet/{petId}` + * + * Find pet by ID + * + * @param int $petId ID of pet to return (required) + * + */ + public function getPetByIdStream(int $petId): void + { + throw new \Exception('Not implemented'); + } /** * Operation updatePet - * Path: /pet + * + * Path: `/pet` * * Update an existing pet * @@ -138,9 +191,24 @@ public function updatePet(\OpenAPIServer\Model\Pet $pet): \OpenAPIServer\Model\P throw new \Exception('Not implemented'); } + /** + * Operation updatePet (stream) + * + * Path: `/pet` + * + * Update an existing pet + * + * @param \OpenAPIServer\Model\Pet $pet Pet object that needs to be added to the store (required) + * + */ + public function updatePetStream(\OpenAPIServer\Model\Pet $pet): void + { + throw new \Exception('Not implemented'); + } /** * Operation updatePetWithForm - * Path: /pet/{petId} + * + * Path: `/pet/{petId}` * * Updates a pet in the store with form data * @@ -153,9 +221,24 @@ public function updatePetWithForm(int $petId): void throw new \Exception('Not implemented'); } + /** + * Operation updatePetWithForm (stream) + * + * Path: `/pet/{petId}` + * + * Updates a pet in the store with form data + * + * @param int $petId ID of pet that needs to be updated (required) + * + */ + public function updatePetWithFormStream(int $petId): void + { + throw new \Exception('Not implemented'); + } /** * Operation uploadFile - * Path: /pet/{petId}/uploadImage + * + * Path: `/pet/{petId}/uploadImage` * * uploads an image * @@ -168,4 +251,18 @@ public function uploadFile(int $petId): \OpenAPIServer\Model\ApiResponse|null throw new \Exception('Not implemented'); } + /** + * Operation uploadFile (stream) + * + * Path: `/pet/{petId}/uploadImage` + * + * uploads an image + * + * @param int $petId ID of pet to update (required) + * + */ + public function uploadFileStream(int $petId): void + { + throw new \Exception('Not implemented'); + } } diff --git a/samples/server/petstore/php-flight/Api/AbstractStoreApi.php b/samples/server/petstore/php-flight/Api/AbstractStoreApi.php index 9c78d8b22b64..6bcc04d92020 100644 --- a/samples/server/petstore/php-flight/Api/AbstractStoreApi.php +++ b/samples/server/petstore/php-flight/Api/AbstractStoreApi.php @@ -23,7 +23,8 @@ abstract class AbstractStoreApi /** * Operation deleteOrder - * Path: /store/order/{orderId} + * + * Path: `/store/order/{orderId}` * * Delete purchase order by ID * @@ -36,9 +37,24 @@ public function deleteOrder(string $orderId): void throw new \Exception('Not implemented'); } + /** + * Operation deleteOrder (stream) + * + * Path: `/store/order/{orderId}` + * + * Delete purchase order by ID + * + * @param string $orderId ID of the order that needs to be deleted (required) + * + */ + public function deleteOrderStream(string $orderId): void + { + throw new \Exception('Not implemented'); + } /** * Operation getInventory - * Path: /store/inventory + * + * Path: `/store/inventory` * * Returns pet inventories by status * @@ -53,6 +69,8 @@ public function getInventory(): void /** * Operation getInventory (stream) * + * Path: `/store/inventory` + * * Returns pet inventories by status * * @@ -63,7 +81,8 @@ public function getInventoryStream(): void } /** * Operation getOrderById - * Path: /store/order/{orderId} + * + * Path: `/store/order/{orderId}` * * Find purchase order by ID * @@ -76,9 +95,24 @@ public function getOrderById(int $orderId): \OpenAPIServer\Model\Order|null throw new \Exception('Not implemented'); } + /** + * Operation getOrderById (stream) + * + * Path: `/store/order/{orderId}` + * + * Find purchase order by ID + * + * @param int $orderId ID of pet that needs to be fetched (required) + * + */ + public function getOrderByIdStream(int $orderId): void + { + throw new \Exception('Not implemented'); + } /** * Operation placeOrder - * Path: /store/order + * + * Path: `/store/order` * * Place an order for a pet * @@ -91,4 +125,18 @@ public function placeOrder(\OpenAPIServer\Model\Order $order): \OpenAPIServer\Mo throw new \Exception('Not implemented'); } + /** + * Operation placeOrder (stream) + * + * Path: `/store/order` + * + * Place an order for a pet + * + * @param \OpenAPIServer\Model\Order $order order placed for purchasing the pet (required) + * + */ + public function placeOrderStream(\OpenAPIServer\Model\Order $order): void + { + throw new \Exception('Not implemented'); + } } diff --git a/samples/server/petstore/php-flight/Api/AbstractUserApi.php b/samples/server/petstore/php-flight/Api/AbstractUserApi.php index 637a299b5e9e..66a16706268a 100644 --- a/samples/server/petstore/php-flight/Api/AbstractUserApi.php +++ b/samples/server/petstore/php-flight/Api/AbstractUserApi.php @@ -23,7 +23,8 @@ abstract class AbstractUserApi /** * Operation createUser - * Path: /user + * + * Path: `/user` * * Create user * @@ -36,9 +37,24 @@ public function createUser(\OpenAPIServer\Model\User $user): void throw new \Exception('Not implemented'); } + /** + * Operation createUser (stream) + * + * Path: `/user` + * + * Create user + * + * @param \OpenAPIServer\Model\User $user Created user object (required) + * + */ + public function createUserStream(\OpenAPIServer\Model\User $user): void + { + throw new \Exception('Not implemented'); + } /** * Operation createUsersWithArrayInput - * Path: /user/createWithArray + * + * Path: `/user/createWithArray` * * Creates list of users with given input array * @@ -51,9 +67,24 @@ public function createUsersWithArrayInput(array $user): void throw new \Exception('Not implemented'); } + /** + * Operation createUsersWithArrayInput (stream) + * + * Path: `/user/createWithArray` + * + * Creates list of users with given input array + * + * @param array $user List of user object (required) + * + */ + public function createUsersWithArrayInputStream(array $user): void + { + throw new \Exception('Not implemented'); + } /** * Operation createUsersWithListInput - * Path: /user/createWithList + * + * Path: `/user/createWithList` * * Creates list of users with given input array * @@ -66,9 +97,24 @@ public function createUsersWithListInput(array $user): void throw new \Exception('Not implemented'); } + /** + * Operation createUsersWithListInput (stream) + * + * Path: `/user/createWithList` + * + * Creates list of users with given input array + * + * @param array $user List of user object (required) + * + */ + public function createUsersWithListInputStream(array $user): void + { + throw new \Exception('Not implemented'); + } /** * Operation deleteUser - * Path: /user/{username} + * + * Path: `/user/{username}` * * Delete user * @@ -81,9 +127,24 @@ public function deleteUser(string $username): void throw new \Exception('Not implemented'); } + /** + * Operation deleteUser (stream) + * + * Path: `/user/{username}` + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * + */ + public function deleteUserStream(string $username): void + { + throw new \Exception('Not implemented'); + } /** * Operation getUserByName - * Path: /user/{username} + * + * Path: `/user/{username}` * * Get user by user name * @@ -96,9 +157,24 @@ public function getUserByName(string $username): \OpenAPIServer\Model\User|null throw new \Exception('Not implemented'); } + /** + * Operation getUserByName (stream) + * + * Path: `/user/{username}` + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * + */ + public function getUserByNameStream(string $username): void + { + throw new \Exception('Not implemented'); + } /** * Operation loginUser - * Path: /user/login + * + * Path: `/user/login` * * Logs user into the system * @@ -112,9 +188,25 @@ public function loginUser(string $username, string $password): string|null throw new \Exception('Not implemented'); } + /** + * Operation loginUser (stream) + * + * Path: `/user/login` + * + * Logs user into the system + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * + */ + public function loginUserStream(string $username, string $password): void + { + throw new \Exception('Not implemented'); + } /** * Operation logoutUser - * Path: /user/logout + * + * Path: `/user/logout` * * Logs out current logged in user session * @@ -126,9 +218,23 @@ public function logoutUser(): void throw new \Exception('Not implemented'); } + /** + * Operation logoutUser (stream) + * + * Path: `/user/logout` + * + * Logs out current logged in user session + * + * + */ + public function logoutUserStream(): void + { + throw new \Exception('Not implemented'); + } /** * Operation updateUser - * Path: /user/{username} + * + * Path: `/user/{username}` * * Updated user * @@ -142,4 +248,19 @@ public function updateUser(string $username, \OpenAPIServer\Model\User $user): v throw new \Exception('Not implemented'); } + /** + * Operation updateUser (stream) + * + * Path: `/user/{username}` + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \OpenAPIServer\Model\User $user Updated user object (required) + * + */ + public function updateUserStream(string $username, \OpenAPIServer\Model\User $user): void + { + throw new \Exception('Not implemented'); + } } diff --git a/samples/server/petstore/php-flight/RegisterRoutes.php b/samples/server/petstore/php-flight/RegisterRoutes.php index 0ac69e994571..abae0ec3bd8f 100644 --- a/samples/server/petstore/php-flight/RegisterRoutes.php +++ b/samples/server/petstore/php-flight/RegisterRoutes.php @@ -33,12 +33,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\Pet') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'addPetStream')) { + \Flight::route('POST /pet', function () use ($handler) { + $r = \Flight::request(); + $handler->addPetStream( + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\Pet') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'deletePet') && declaresMethod($reflectionClass, 'deletePetStream')) { throw new \Exception('Operation deletePet cannot be both streaming and non-streaming'); @@ -50,9 +59,19 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($petId, 'int'), parseParam($r->getHeader('api_key'), '?string') ); - \Flight::halt(204); + \Flight::halt(400); }); } + if (declaresMethod($reflectionClass, 'deletePetStream')) { + \Flight::route('DELETE /pet/@petId', function (string $petId) use ($handler) { + $r = \Flight::request(); + $handler->deletePetStream( + parseParam($petId, 'int'), + parseParam($r->getHeader('api_key'), '?string') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 400]); + } if (declaresMethod($reflectionClass, 'findPetsByStatus') && declaresMethod($reflectionClass, 'findPetsByStatusStream')) { throw new \Exception('Operation findPetsByStatus cannot be both streaming and non-streaming'); @@ -64,9 +83,9 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($r->query['status'] ?? null, '\\OpenAPIServer\\Model\\FindPetsByStatusStatusParameterInner[]') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } @@ -77,7 +96,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($r->query['status'] ?? null, '\\OpenAPIServer\\Model\\FindPetsByStatusStatusParameterInner[]') ); // ignore return value: streaming expected - })->streamWithHeaders(['Content-Type' => 'application/json']); + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); } if (declaresMethod($reflectionClass, 'findPetsByTags') && declaresMethod($reflectionClass, 'findPetsByTagsStream')) { @@ -90,9 +109,9 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($r->query['tags'] ?? null, 'string[]') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } @@ -103,7 +122,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($r->query['tags'] ?? null, 'string[]') ); // ignore return value: streaming expected - })->streamWithHeaders(['Content-Type' => 'application/json']); + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); } if (declaresMethod($reflectionClass, 'getPetById') && declaresMethod($reflectionClass, 'getPetByIdStream')) { @@ -116,12 +135,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($petId, 'int') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'getPetByIdStream')) { + \Flight::route('GET /pet/@petId', function (string $petId) use ($handler) { + $r = \Flight::request(); + $handler->getPetByIdStream( + parseParam($petId, 'int') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'updatePet') && declaresMethod($reflectionClass, 'updatePetStream')) { throw new \Exception('Operation updatePet cannot be both streaming and non-streaming'); @@ -133,12 +161,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\Pet') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'updatePetStream')) { + \Flight::route('PUT /pet', function () use ($handler) { + $r = \Flight::request(); + $handler->updatePetStream( + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\Pet') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'updatePetWithForm') && declaresMethod($reflectionClass, 'updatePetWithFormStream')) { throw new \Exception('Operation updatePetWithForm cannot be both streaming and non-streaming'); @@ -149,9 +186,18 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->updatePetWithForm( parseParam($petId, 'int') ); - \Flight::halt(204); + \Flight::halt(405); }); } + if (declaresMethod($reflectionClass, 'updatePetWithFormStream')) { + \Flight::route('POST /pet/@petId', function (string $petId) use ($handler) { + $r = \Flight::request(); + $handler->updatePetWithFormStream( + parseParam($petId, 'int') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 405]); + } if (declaresMethod($reflectionClass, 'uploadFile') && declaresMethod($reflectionClass, 'uploadFileStream')) { throw new \Exception('Operation uploadFile cannot be both streaming and non-streaming'); @@ -163,12 +209,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($petId, 'int') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'uploadFileStream')) { + \Flight::route('POST /pet/@petId/uploadImage', function (string $petId) use ($handler) { + $r = \Flight::request(); + $handler->uploadFileStream( + parseParam($petId, 'int') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'deleteOrder') && declaresMethod($reflectionClass, 'deleteOrderStream')) { throw new \Exception('Operation deleteOrder cannot be both streaming and non-streaming'); @@ -179,9 +234,18 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->deleteOrder( parseParam($orderId, 'string') ); - \Flight::halt(204); + \Flight::halt(400); }); } + if (declaresMethod($reflectionClass, 'deleteOrderStream')) { + \Flight::route('DELETE /store/order/@orderId', function (string $orderId) use ($handler) { + $r = \Flight::request(); + $handler->deleteOrderStream( + parseParam($orderId, 'string') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 400]); + } if (declaresMethod($reflectionClass, 'getInventory') && declaresMethod($reflectionClass, 'getInventoryStream')) { throw new \Exception('Operation getInventory cannot be both streaming and non-streaming'); @@ -191,7 +255,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $r = \Flight::request(); $handler->getInventory( ); - \Flight::halt(204); + \Flight::halt(200); }); } if (declaresMethod($reflectionClass, 'getInventoryStream')) { @@ -200,7 +264,7 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->getInventoryStream( ); // ignore return value: streaming expected - })->streamWithHeaders(['Content-Type' => 'application/json']); + })->streamWithHeaders(['status' => 200]); } if (declaresMethod($reflectionClass, 'getOrderById') && declaresMethod($reflectionClass, 'getOrderByIdStream')) { @@ -213,12 +277,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($orderId, 'int') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'getOrderByIdStream')) { + \Flight::route('GET /store/order/@orderId', function (string $orderId) use ($handler) { + $r = \Flight::request(); + $handler->getOrderByIdStream( + parseParam($orderId, 'int') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'placeOrder') && declaresMethod($reflectionClass, 'placeOrderStream')) { throw new \Exception('Operation placeOrder cannot be both streaming and non-streaming'); @@ -230,12 +303,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\Order') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'placeOrderStream')) { + \Flight::route('POST /store/order', function () use ($handler) { + $r = \Flight::request(); + $handler->placeOrderStream( + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\Order') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'createUser') && declaresMethod($reflectionClass, 'createUserStream')) { throw new \Exception('Operation createUser cannot be both streaming and non-streaming'); @@ -246,9 +328,18 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->createUser( parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User') ); - \Flight::halt(204); + \Flight::halt(200); }); } + if (declaresMethod($reflectionClass, 'createUserStream')) { + \Flight::route('POST /user', function () use ($handler) { + $r = \Flight::request(); + $handler->createUserStream( + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200]); + } if (declaresMethod($reflectionClass, 'createUsersWithArrayInput') && declaresMethod($reflectionClass, 'createUsersWithArrayInputStream')) { throw new \Exception('Operation createUsersWithArrayInput cannot be both streaming and non-streaming'); @@ -259,9 +350,18 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->createUsersWithArrayInput( parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User[]') ); - \Flight::halt(204); + \Flight::halt(200); }); } + if (declaresMethod($reflectionClass, 'createUsersWithArrayInputStream')) { + \Flight::route('POST /user/createWithArray', function () use ($handler) { + $r = \Flight::request(); + $handler->createUsersWithArrayInputStream( + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User[]') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200]); + } if (declaresMethod($reflectionClass, 'createUsersWithListInput') && declaresMethod($reflectionClass, 'createUsersWithListInputStream')) { throw new \Exception('Operation createUsersWithListInput cannot be both streaming and non-streaming'); @@ -272,9 +372,18 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->createUsersWithListInput( parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User[]') ); - \Flight::halt(204); + \Flight::halt(200); }); } + if (declaresMethod($reflectionClass, 'createUsersWithListInputStream')) { + \Flight::route('POST /user/createWithList', function () use ($handler) { + $r = \Flight::request(); + $handler->createUsersWithListInputStream( + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User[]') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200]); + } if (declaresMethod($reflectionClass, 'deleteUser') && declaresMethod($reflectionClass, 'deleteUserStream')) { throw new \Exception('Operation deleteUser cannot be both streaming and non-streaming'); @@ -285,9 +394,18 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $handler->deleteUser( parseParam($username, 'string') ); - \Flight::halt(204); + \Flight::halt(400); }); } + if (declaresMethod($reflectionClass, 'deleteUserStream')) { + \Flight::route('DELETE /user/@username', function (string $username) use ($handler) { + $r = \Flight::request(); + $handler->deleteUserStream( + parseParam($username, 'string') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 400]); + } if (declaresMethod($reflectionClass, 'getUserByName') && declaresMethod($reflectionClass, 'getUserByNameStream')) { throw new \Exception('Operation getUserByName cannot be both streaming and non-streaming'); @@ -299,12 +417,21 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($username, 'string') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'getUserByNameStream')) { + \Flight::route('GET /user/@username', function (string $username) use ($handler) { + $r = \Flight::request(); + $handler->getUserByNameStream( + parseParam($username, 'string') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'loginUser') && declaresMethod($reflectionClass, 'loginUserStream')) { throw new \Exception('Operation loginUser cannot be both streaming and non-streaming'); @@ -317,12 +444,22 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($r->query['password'] ?? null, 'string') ); if ($result === null) { - \Flight::halt(204); + \Flight::halt(200); } else { - \Flight::json($result); + \Flight::json($result, 200); } }); } + if (declaresMethod($reflectionClass, 'loginUserStream')) { + \Flight::route('GET /user/login', function () use ($handler) { + $r = \Flight::request(); + $handler->loginUserStream( + parseParam($r->query['username'] ?? null, 'string'), + parseParam($r->query['password'] ?? null, 'string') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200, 'Content-Type' => 'application/json']); + } if (declaresMethod($reflectionClass, 'logoutUser') && declaresMethod($reflectionClass, 'logoutUserStream')) { throw new \Exception('Operation logoutUser cannot be both streaming and non-streaming'); @@ -332,9 +469,17 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI $r = \Flight::request(); $handler->logoutUser( ); - \Flight::halt(204); + \Flight::halt(200); }); } + if (declaresMethod($reflectionClass, 'logoutUserStream')) { + \Flight::route('GET /user/logout', function () use ($handler) { + $r = \Flight::request(); + $handler->logoutUserStream( + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 200]); + } if (declaresMethod($reflectionClass, 'updateUser') && declaresMethod($reflectionClass, 'updateUserStream')) { throw new \Exception('Operation updateUser cannot be both streaming and non-streaming'); @@ -346,9 +491,19 @@ static public function registerRoutes(\OpenAPIServer\Api\AbstractPetApi|\OpenAPI parseParam($username, 'string'), parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User') ); - \Flight::halt(204); + \Flight::halt(400); }); } + if (declaresMethod($reflectionClass, 'updateUserStream')) { + \Flight::route('PUT /user/@username', function (string $username) use ($handler) { + $r = \Flight::request(); + $handler->updateUserStream( + parseParam($username, 'string'), + parseParam(json_decode($r->getBody(), true), '\\OpenAPIServer\\Model\\User') + ); + // ignore return value: streaming expected + })->streamWithHeaders(['status' => 400]); + } } }