From 4d6d63754d561ece861461dd4ca7df0863a1ab90 Mon Sep 17 00:00:00 2001 From: abcsun Date: Fri, 13 May 2016 11:43:29 +0800 Subject: [PATCH 1/3] add parameters validation from request & adjust the mustache output style --- bin/lumen-petstore-server.sh | 2 +- .../resources/lumen/app/Http/routes.mustache | 52 ++- .../src/main/resources/lumen/routes.mustache | 28 -- .../petstore/lumen/lumen/app/Http/routes.php | 352 ++++++++++++------ 4 files changed, 291 insertions(+), 143 deletions(-) delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/routes.mustache diff --git a/bin/lumen-petstore-server.sh b/bin/lumen-petstore-server.sh index 15acb2fe2bd3..a4a5df0f817d 100755 --- a/bin/lumen-petstore-server.sh +++ b/bin/lumen-petstore-server.sh @@ -26,6 +26,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="$@ generate -t modules/swagger-codegen/src/main/resources/lumen -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l lumen -o samples/server/petstore/lumen" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/lumen -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l lumen -o samples/server/petstore/lumen" java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Http/routes.mustache b/modules/swagger-codegen/src/main/resources/lumen/app/Http/routes.mustache index 3166f9479357..ccef81b0456f 100644 --- a/modules/swagger-codegen/src/main/resources/lumen/app/Http/routes.mustache +++ b/modules/swagger-codegen/src/main/resources/lumen/app/Http/routes.mustache @@ -8,7 +8,9 @@ $app->get('/', function () use ($app) { return $app->version(); }); -{{#apis}}{{#operations}}{{#operation}} +{{#apis}} +{{#operations}} +{{#operation}} /** * {{httpMethod}} {{nickname}} * Summary: {{summary}} @@ -16,13 +18,49 @@ $app->get('/', function () use ($app) { {{#hasProduces}} * Output-Formats: [{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}]{{/hasProduces}} */ $app->{{httpMethod}}('{{path}}', function({{#pathParams}}${{paramName}}, {{/pathParams}}$null = null) use ($app) { - {{#hasHeaderParams}}$headers = Request::header();{{/hasHeaderParams}} - {{#hasQueryParams}}{{#queryParams}}${{paramName}} = Request::input('{{paramName}}');{{newline}} - {{/queryParams}}{{/hasQueryParams}} - {{#hasFormParams}}{{#formParams}}${{paramName}} = Request::input('{{paramName}}');{{newline}} {{/formParams}}{{/hasFormParams}} + $input = Request::all(); + {{#allParams}} + {{#required}} + if (!isset($input['{{paramName}}'])) { + throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{operationId}}'); + } + {{/required}} + {{#hasValidation}} + {{#maxLength}} + if (strlen($input['{{paramName}}']) > {{maxLength}}) { + throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); + } + {{/maxLength}} + {{#minLength}} + if (strlen($input['{{paramName}}']) < {{minLength}}) { + throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); + } + {{/minLength}} + {{#maximum}} + if ($input['{{paramName}}'] > {{maximum}}) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maximum}}.'); + } + {{/maximum}} + {{#minimum}} + if ($input['{{paramName}}'] < {{minimum}}) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minimum}}.'); + } + {{/minimum}} + {{#pattern}} + if (!preg_match("{{pattern}}", $input['{{paramName}}'])) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{pattern}}.'); + } + {{/pattern}} + {{/hasValidation}} + ${{paramName}} = $input['{{paramName}}']; + + {{/allParams}} return response('How about implementing {{nickname}} as a {{httpMethod}} method ?'); - }); +}); -{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} diff --git a/modules/swagger-codegen/src/main/resources/lumen/routes.mustache b/modules/swagger-codegen/src/main/resources/lumen/routes.mustache deleted file mode 100644 index be2fac8d86e5..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/routes.mustache +++ /dev/null @@ -1,28 +0,0 @@ -get('/', function () use ($app) { - return $app->version(); -}); - -{{#apis}}{{#operations}}{{#operation}} -/** - * {{httpMethod}} {{nickname}} - * Summary: {{summary}} - * Notes: {{notes}} -{{#hasProduces}} * Output-Formats: [{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}]{{/hasProduces}} - */ -Route::{{httpMethod}}('{{path}}', function({{#pathParams}}${{paramName}}, {{/pathParams}}null) use ($app) { - {{#hasHeaderParams}}$headers = Request::header();{{/hasHeaderParams}} - {{#hasQueryParams}}{{#queryParams}}${{paramName}} = Request::input('{{paramName}}');{{newline}} - {{/queryParams}}{{/hasQueryParams}} - {{#hasFormParams}}{{#formParams}}${{paramName}} = Request::input('{{paramName}}');{{newline}} {{/formParams}}{{/hasFormParams}} - - return response('How about implementing {{nickname}} as a {{httpMethod}} method ?'); - }); - -{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} - diff --git a/samples/server/petstore/lumen/lumen/app/Http/routes.php b/samples/server/petstore/lumen/lumen/app/Http/routes.php index 4e657ca14830..b4147ae7f61c 100644 --- a/samples/server/petstore/lumen/lumen/app/Http/routes.php +++ b/samples/server/petstore/lumen/lumen/app/Http/routes.php @@ -8,6 +8,89 @@ $app->get('/', function () use ($app) { return $app->version(); }); +/** + * POST testEndpointParameters + * Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/fake', function($null = null) use ($app) { + $input = Request::all(); + + if (!isset($input['number'])) { + throw new \InvalidArgumentException('Missing the required parameter $number when calling testEndpointParameters'); + } + if ($input['number'] > 543.2) { + throw new \InvalidArgumentException('invalid value for $number when calling FakeApi.testEndpointParameters, must be smaller than or equal to 543.2.'); + } + if ($input['number'] < 32.1) { + throw new \InvalidArgumentException('invalid value for $number when calling FakeApi.testEndpointParameters, must be bigger than or equal to 32.1.'); + } + $number = $input['number']; + + if (!isset($input['double'])) { + throw new \InvalidArgumentException('Missing the required parameter $double when calling testEndpointParameters'); + } + if ($input['double'] > 123.4) { + throw new \InvalidArgumentException('invalid value for $double when calling FakeApi.testEndpointParameters, must be smaller than or equal to 123.4.'); + } + if ($input['double'] < 67.8) { + throw new \InvalidArgumentException('invalid value for $double when calling FakeApi.testEndpointParameters, must be bigger than or equal to 67.8.'); + } + $double = $input['double']; + + if (!isset($input['string'])) { + throw new \InvalidArgumentException('Missing the required parameter $string when calling testEndpointParameters'); + } + if (!preg_match("/[a-z]/i", $input['string'])) { + throw new \InvalidArgumentException('invalid value for $string when calling FakeApi.testEndpointParameters, must conform to the pattern /[a-z]/i.'); + } + $string = $input['string']; + + if (!isset($input['byte'])) { + throw new \InvalidArgumentException('Missing the required parameter $byte when calling testEndpointParameters'); + } + $byte = $input['byte']; + + if ($input['integer'] > 100.0) { + throw new \InvalidArgumentException('invalid value for $integer when calling FakeApi.testEndpointParameters, must be smaller than or equal to 100.0.'); + } + if ($input['integer'] < 10.0) { + throw new \InvalidArgumentException('invalid value for $integer when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.0.'); + } + $integer = $input['integer']; + + if ($input['int32'] > 200.0) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FakeApi.testEndpointParameters, must be smaller than or equal to 200.0.'); + } + if ($input['int32'] < 20.0) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FakeApi.testEndpointParameters, must be bigger than or equal to 20.0.'); + } + $int32 = $input['int32']; + + $int64 = $input['int64']; + + if ($input['float'] > 987.6) { + throw new \InvalidArgumentException('invalid value for $float when calling FakeApi.testEndpointParameters, must be smaller than or equal to 987.6.'); + } + $float = $input['float']; + + $binary = $input['binary']; + + $date = $input['date']; + + $dateTime = $input['dateTime']; + + if (strlen($input['password']) > 64) { + throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be smaller than or equal to 64.'); + } + if (strlen($input['password']) < 10) { + throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.'); + } + $password = $input['password']; + + return response('How about implementing testEndpointParameters as a POST method ?'); +}); /** * POST addPet @@ -16,13 +99,15 @@ $app->get('/', function () use ($app) { * Output-Formats: [application/xml, application/json] */ $app->POST('/pet', function($null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling addPet'); + } + $body = $input['body']; return response('How about implementing addPet as a POST method ?'); - }); - +}); /** * DELETE deletePet @@ -31,13 +116,17 @@ $app->POST('/pet', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->DELETE('/pet/{petId}', function($petId, $null = null) use ($app) { - $headers = Request::header(); - - + $input = Request::all(); + + if (!isset($input['petId'])) { + throw new \InvalidArgumentException('Missing the required parameter $petId when calling deletePet'); + } + $petId = $input['petId']; + + $apiKey = $input['apiKey']; return response('How about implementing deletePet as a DELETE method ?'); - }); - +}); /** * GET findPetsByStatus @@ -46,30 +135,32 @@ $app->DELETE('/pet/{petId}', function($petId, $null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->GET('/pet/findByStatus', function($null = null) use ($app) { - - $status = Request::input('status'); - - + $input = Request::all(); + + if (!isset($input['status'])) { + throw new \InvalidArgumentException('Missing the required parameter $status when calling findPetsByStatus'); + } + $status = $input['status']; return response('How about implementing findPetsByStatus as a GET method ?'); - }); - +}); /** * GET findPetsByTags * Summary: Finds Pets by tags - * Notes: Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * Notes: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * Output-Formats: [application/xml, application/json] */ $app->GET('/pet/findByTags', function($null = null) use ($app) { - - $tags = Request::input('tags'); - - + $input = Request::all(); + + if (!isset($input['tags'])) { + throw new \InvalidArgumentException('Missing the required parameter $tags when calling findPetsByTags'); + } + $tags = $input['tags']; return response('How about implementing findPetsByTags as a GET method ?'); - }); - +}); /** * GET getPetById @@ -78,13 +169,15 @@ $app->GET('/pet/findByTags', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->GET('/pet/{petId}', function($petId, $null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['petId'])) { + throw new \InvalidArgumentException('Missing the required parameter $petId when calling getPetById'); + } + $petId = $input['petId']; return response('How about implementing getPetById as a GET method ?'); - }); - +}); /** * PUT updatePet @@ -93,13 +186,15 @@ $app->GET('/pet/{petId}', function($petId, $null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->PUT('/pet', function($null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling updatePet'); + } + $body = $input['body']; return response('How about implementing updatePet as a PUT method ?'); - }); - +}); /** * POST updatePetWithForm @@ -108,13 +203,19 @@ $app->PUT('/pet', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->POST('/pet/{petId}', function($petId, $null = null) use ($app) { - - - $name = Request::input('name'); $status = Request::input('status'); + $input = Request::all(); + + if (!isset($input['petId'])) { + throw new \InvalidArgumentException('Missing the required parameter $petId when calling updatePetWithForm'); + } + $petId = $input['petId']; + + $name = $input['name']; + + $status = $input['status']; return response('How about implementing updatePetWithForm as a POST method ?'); - }); - +}); /** * POST uploadFile @@ -123,28 +224,39 @@ $app->POST('/pet/{petId}', function($petId, $null = null) use ($app) { * Output-Formats: [application/json] */ $app->POST('/pet/{petId}/uploadImage', function($petId, $null = null) use ($app) { - - - $additionalMetadata = Request::input('additionalMetadata'); $file = Request::input('file'); + $input = Request::all(); + + if (!isset($input['petId'])) { + throw new \InvalidArgumentException('Missing the required parameter $petId when calling uploadFile'); + } + $petId = $input['petId']; + + $additionalMetadata = $input['additionalMetadata']; + + $file = $input['file']; return response('How about implementing uploadFile as a POST method ?'); - }); - +}); /** * DELETE deleteOrder * Summary: Delete purchase order by ID - * Notes: For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors + * Notes: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * Output-Formats: [application/xml, application/json] */ $app->DELETE('/store/order/{orderId}', function($orderId, $null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['orderId'])) { + throw new \InvalidArgumentException('Missing the required parameter $orderId when calling deleteOrder'); + } + if ($input['orderId'] < 1.0) { + throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.deleteOrder, must be bigger than or equal to 1.0.'); + } + $orderId = $input['orderId']; return response('How about implementing deleteOrder as a DELETE method ?'); - }); - +}); /** * GET getInventory @@ -153,28 +265,33 @@ $app->DELETE('/store/order/{orderId}', function($orderId, $null = null) use ($ap * Output-Formats: [application/json] */ $app->GET('/store/inventory', function($null = null) use ($app) { - - - + $input = Request::all(); return response('How about implementing getInventory as a GET method ?'); - }); - +}); /** * GET getOrderById * Summary: Find purchase order by ID - * Notes: For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + * Notes: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * Output-Formats: [application/xml, application/json] */ $app->GET('/store/order/{orderId}', function($orderId, $null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['orderId'])) { + throw new \InvalidArgumentException('Missing the required parameter $orderId when calling getOrderById'); + } + if ($input['orderId'] > 5.0) { + throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.getOrderById, must be smaller than or equal to 5.0.'); + } + if ($input['orderId'] < 1.0) { + throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.getOrderById, must be bigger than or equal to 1.0.'); + } + $orderId = $input['orderId']; return response('How about implementing getOrderById as a GET method ?'); - }); - +}); /** * POST placeOrder @@ -183,13 +300,15 @@ $app->GET('/store/order/{orderId}', function($orderId, $null = null) use ($app) * Output-Formats: [application/xml, application/json] */ $app->POST('/store/order', function($null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling placeOrder'); + } + $body = $input['body']; return response('How about implementing placeOrder as a POST method ?'); - }); - +}); /** * POST createUser @@ -198,13 +317,15 @@ $app->POST('/store/order', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->POST('/user', function($null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling createUser'); + } + $body = $input['body']; return response('How about implementing createUser as a POST method ?'); - }); - +}); /** * POST createUsersWithArrayInput @@ -213,13 +334,15 @@ $app->POST('/user', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->POST('/user/createWithArray', function($null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling createUsersWithArrayInput'); + } + $body = $input['body']; return response('How about implementing createUsersWithArrayInput as a POST method ?'); - }); - +}); /** * POST createUsersWithListInput @@ -228,13 +351,15 @@ $app->POST('/user/createWithArray', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->POST('/user/createWithList', function($null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling createUsersWithListInput'); + } + $body = $input['body']; return response('How about implementing createUsersWithListInput as a POST method ?'); - }); - +}); /** * DELETE deleteUser @@ -243,13 +368,15 @@ $app->POST('/user/createWithList', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->DELETE('/user/{username}', function($username, $null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['username'])) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); + } + $username = $input['username']; return response('How about implementing deleteUser as a DELETE method ?'); - }); - +}); /** * GET getUserByName @@ -258,13 +385,15 @@ $app->DELETE('/user/{username}', function($username, $null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->GET('/user/{username}', function($username, $null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['username'])) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); + } + $username = $input['username']; return response('How about implementing getUserByName as a GET method ?'); - }); - +}); /** * GET loginUser @@ -273,15 +402,20 @@ $app->GET('/user/{username}', function($username, $null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->GET('/user/login', function($null = null) use ($app) { - - $username = Request::input('username'); - $password = Request::input('password'); - - + $input = Request::all(); + + if (!isset($input['username'])) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling loginUser'); + } + $username = $input['username']; + + if (!isset($input['password'])) { + throw new \InvalidArgumentException('Missing the required parameter $password when calling loginUser'); + } + $password = $input['password']; return response('How about implementing loginUser as a GET method ?'); - }); - +}); /** * GET logoutUser @@ -290,13 +424,10 @@ $app->GET('/user/login', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->GET('/user/logout', function($null = null) use ($app) { - - - + $input = Request::all(); return response('How about implementing logoutUser as a GET method ?'); - }); - +}); /** * PUT updateUser @@ -305,12 +436,19 @@ $app->GET('/user/logout', function($null = null) use ($app) { * Output-Formats: [application/xml, application/json] */ $app->PUT('/user/{username}', function($username, $null = null) use ($app) { - - - + $input = Request::all(); + + if (!isset($input['username'])) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); + } + $username = $input['username']; + + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling updateUser'); + } + $body = $input['body']; return response('How about implementing updateUser as a PUT method ?'); - }); - +}); From ee024c40fb52d3d6566b489e22806249836b0287 Mon Sep 17 00:00:00 2001 From: abcsun Date: Mon, 13 Jun 2016 17:37:19 +0800 Subject: [PATCH 2/3] add apache license to lumen --- .../resources/lumen/app/Console/Kernel.php | 18 ++ .../lumen/app/Exceptions/Handler.php | 18 ++ .../lumen/app/Http/Controllers/Controller.php | 18 ++ .../Http/Controllers/ExampleController.php | 18 ++ .../app/Http/Middleware/Authenticate.php | 18 ++ .../app/Http/Middleware/ExampleMiddleware.php | 18 ++ .../resources/lumen/app/Http/routes.mustache | 2 + .../app/Providers/AppServiceProvider.php | 18 ++ .../app/Providers/AuthServiceProvider.php | 18 ++ .../app/Providers/EventServiceProvider.php | 18 ++ .../src/main/resources/lumen/app/User.php | 18 ++ .../main/resources/lumen/bootstrap/app.php | 18 ++ .../src/main/resources/lumen/composer.json | 2 +- .../main/resources/lumen/licenseinfo.mustache | 23 ++ .../src/main/resources/lumen/public/index.php | 18 ++ .../src/main/resources/lumen/readme.md | 3 - .../petstore/lumen/.swagger-codegen-ignore | 23 ++ samples/server/petstore/lumen/LICENSE | 201 ++++++++++++++++++ .../lumen/lumen/app/Console/Kernel.php | 18 ++ .../lumen/lumen/app/Exceptions/Handler.php | 18 ++ .../lumen/app/Http/Controllers/Controller.php | 18 ++ .../Http/Controllers/ExampleController.php | 18 ++ .../app/Http/Middleware/Authenticate.php | 18 ++ .../app/Http/Middleware/ExampleMiddleware.php | 18 ++ .../petstore/lumen/lumen/app/Http/routes.php | 27 ++- .../app/Providers/AppServiceProvider.php | 18 ++ .../app/Providers/AuthServiceProvider.php | 18 ++ .../app/Providers/EventServiceProvider.php | 18 ++ .../server/petstore/lumen/lumen/app/User.php | 18 ++ .../petstore/lumen/lumen/bootstrap/app.php | 18 ++ .../server/petstore/lumen/lumen/composer.json | 2 +- .../petstore/lumen/lumen/public/index.php | 18 ++ samples/server/petstore/lumen/lumen/readme.md | 3 - 33 files changed, 709 insertions(+), 9 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/lumen/licenseinfo.mustache create mode 100644 samples/server/petstore/lumen/.swagger-codegen-ignore create mode 100644 samples/server/petstore/lumen/LICENSE diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Console/Kernel.php b/modules/swagger-codegen/src/main/resources/lumen/app/Console/Kernel.php index ad6e311cdd04..6f10d9f838e1 100644 --- a/modules/swagger-codegen/src/main/resources/lumen/app/Console/Kernel.php +++ b/modules/swagger-codegen/src/main/resources/lumen/app/Console/Kernel.php @@ -1,5 +1,23 @@ licenseInfo}} {{#apiInfo}}/** * {{appName}} * @version {{appVersion}} diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php b/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php index ddec04694c37..2c905bd129a2 100644 --- a/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php +++ b/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php @@ -1,5 +1,23 @@ =5.5.9", diff --git a/modules/swagger-codegen/src/main/resources/lumen/licenseinfo.mustache b/modules/swagger-codegen/src/main/resources/lumen/licenseinfo.mustache new file mode 100644 index 000000000000..861d97234cfa --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/lumen/licenseinfo.mustache @@ -0,0 +1,23 @@ +/** + * {{{appName}}} + * {{{appDescription}}} + * + * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} + * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/modules/swagger-codegen/src/main/resources/lumen/public/index.php b/modules/swagger-codegen/src/main/resources/lumen/public/index.php index 04aa08688e00..3fc941322319 100644 --- a/modules/swagger-codegen/src/main/resources/lumen/public/index.php +++ b/modules/swagger-codegen/src/main/resources/lumen/public/index.php @@ -1,5 +1,23 @@ get('/', function () use ($app) { * POST testEndpointParameters * Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 - * Output-Formats: [application/xml, application/json] + * Output-Formats: [application/xml; charset=utf-8, application/json; charset=utf-8] */ $app->POST('/fake', function($null = null) use ($app) { $input = Request::all(); diff --git a/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php b/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php index ddec04694c37..2c905bd129a2 100644 --- a/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php +++ b/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php @@ -1,5 +1,23 @@ =5.5.9", diff --git a/samples/server/petstore/lumen/lumen/public/index.php b/samples/server/petstore/lumen/lumen/public/index.php index 04aa08688e00..3fc941322319 100644 --- a/samples/server/petstore/lumen/lumen/public/index.php +++ b/samples/server/petstore/lumen/lumen/public/index.php @@ -1,5 +1,23 @@ Date: Fri, 17 Jun 2016 11:37:10 +0800 Subject: [PATCH 3/3] add lumen api.mustache to generate controller & license update & resource dir restructure --- .../codegen/languages/LumenServerCodegen.java | 73 +-- .../Http/Middleware => }/Authenticate.php | 0 .../{app/Http/Controllers => }/Controller.php | 0 .../lumen/{app/Exceptions => }/Handler.php | 0 .../lumen/{app/Console => }/Kernel.php | 0 .../main/resources/lumen/{app => }/User.php | 0 .../src/main/resources/lumen/api.mustache | 108 ++++ .../resources/lumen/{bootstrap => }/app.php | 4 +- .../lumen/app/Console/Commands/.gitkeep | 0 .../Http/Controllers/ExampleController.php | 36 -- .../app/Http/Middleware/ExampleMiddleware.php | 38 -- .../resources/lumen/app/Http/routes.mustache | 68 --- .../app/Providers/AppServiceProvider.php | 36 -- .../app/Providers/AuthServiceProvider.php | 58 --- .../app/Providers/EventServiceProvider.php | 37 -- .../src/main/resources/lumen/composer.json | 17 - .../main/resources/lumen/composer.mustache | 31 ++ .../resources/lumen/{public => }/index.php | 0 .../src/main/resources/lumen/public/.htaccess | 16 - .../src/main/resources/lumen/readme.md | 22 +- .../src/main/resources/lumen/routes.mustache | 27 + .../resources/lumen/storage/app/.gitignore | 2 - .../lumen/storage/framework/views/.gitignore | 2 - .../resources/lumen/storage/logs/.gitignore | 2 - .../resources/lumen/tests/ExampleTest.php | 20 - .../main/resources/lumen/tests/TestCase.php | 14 - .../lumen/{lumen => }/app/Console/Kernel.php | 0 .../{lumen => }/app/Exceptions/Handler.php | 0 .../app/Http/Middleware/Authenticate.php | 0 .../Http/controllers}/Controller.php | 0 .../lumen/app/Http/controllers/FakeApi.php | 132 +++++ .../lumen/app/Http/controllers/PetApi.php | 217 ++++++++ .../lumen/app/Http/controllers/StoreApi.php | 133 +++++ .../lumen/app/Http/controllers/UserApi.php | 221 ++++++++ .../server/petstore/lumen/app/Http/routes.php | 183 +++++++ .../petstore/lumen/{lumen => }/app/User.php | 0 .../lumen/{lumen => }/bootstrap/app.php | 4 +- samples/server/petstore/lumen/composer.json | 28 + .../Http/Controllers/ExampleController.php | 36 -- .../app/Http/Middleware/ExampleMiddleware.php | 38 -- .../petstore/lumen/lumen/app/Http/routes.php | 479 ------------------ .../app/Providers/AppServiceProvider.php | 36 -- .../app/Providers/AuthServiceProvider.php | 58 --- .../app/Providers/EventServiceProvider.php | 37 -- samples/server/petstore/lumen/lumen/artisan | 35 -- .../server/petstore/lumen/lumen/composer.json | 17 - samples/server/petstore/lumen/lumen/readme.md | 18 - .../lumen/{lumen => }/public/index.php | 0 samples/server/petstore/lumen/readme.md | 16 + 49 files changed, 1136 insertions(+), 1163 deletions(-) rename modules/swagger-codegen/src/main/resources/lumen/{app/Http/Middleware => }/Authenticate.php (100%) rename modules/swagger-codegen/src/main/resources/lumen/{app/Http/Controllers => }/Controller.php (100%) rename modules/swagger-codegen/src/main/resources/lumen/{app/Exceptions => }/Handler.php (100%) rename modules/swagger-codegen/src/main/resources/lumen/{app/Console => }/Kernel.php (100%) rename modules/swagger-codegen/src/main/resources/lumen/{app => }/User.php (100%) create mode 100644 modules/swagger-codegen/src/main/resources/lumen/api.mustache rename modules/swagger-codegen/src/main/resources/lumen/{bootstrap => }/app.php (96%) delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Console/Commands/.gitkeep delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/ExampleController.php delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Http/Middleware/ExampleMiddleware.php delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Http/routes.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Providers/AuthServiceProvider.php delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/app/Providers/EventServiceProvider.php delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/composer.json create mode 100644 modules/swagger-codegen/src/main/resources/lumen/composer.mustache rename modules/swagger-codegen/src/main/resources/lumen/{public => }/index.php (100%) delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/public/.htaccess create mode 100644 modules/swagger-codegen/src/main/resources/lumen/routes.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/storage/app/.gitignore delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/storage/framework/views/.gitignore delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/storage/logs/.gitignore delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/tests/ExampleTest.php delete mode 100644 modules/swagger-codegen/src/main/resources/lumen/tests/TestCase.php rename samples/server/petstore/lumen/{lumen => }/app/Console/Kernel.php (100%) rename samples/server/petstore/lumen/{lumen => }/app/Exceptions/Handler.php (100%) rename samples/server/petstore/lumen/{lumen => }/app/Http/Middleware/Authenticate.php (100%) rename samples/server/petstore/lumen/{lumen/app/Http/Controllers => app/Http/controllers}/Controller.php (100%) create mode 100644 samples/server/petstore/lumen/app/Http/controllers/FakeApi.php create mode 100644 samples/server/petstore/lumen/app/Http/controllers/PetApi.php create mode 100644 samples/server/petstore/lumen/app/Http/controllers/StoreApi.php create mode 100644 samples/server/petstore/lumen/app/Http/controllers/UserApi.php create mode 100644 samples/server/petstore/lumen/app/Http/routes.php rename samples/server/petstore/lumen/{lumen => }/app/User.php (100%) rename samples/server/petstore/lumen/{lumen => }/bootstrap/app.php (96%) create mode 100644 samples/server/petstore/lumen/composer.json delete mode 100644 samples/server/petstore/lumen/lumen/app/Http/Controllers/ExampleController.php delete mode 100644 samples/server/petstore/lumen/lumen/app/Http/Middleware/ExampleMiddleware.php delete mode 100644 samples/server/petstore/lumen/lumen/app/Http/routes.php delete mode 100644 samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php delete mode 100644 samples/server/petstore/lumen/lumen/app/Providers/AuthServiceProvider.php delete mode 100644 samples/server/petstore/lumen/lumen/app/Providers/EventServiceProvider.php delete mode 100644 samples/server/petstore/lumen/lumen/artisan delete mode 100644 samples/server/petstore/lumen/lumen/composer.json delete mode 100644 samples/server/petstore/lumen/lumen/readme.md rename samples/server/petstore/lumen/{lumen => }/public/index.php (100%) create mode 100644 samples/server/petstore/lumen/readme.md diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LumenServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LumenServerCodegen.java index fbd98c034df0..abc747435bf8 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LumenServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LumenServerCodegen.java @@ -9,9 +9,20 @@ import java.io.File; public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig { // source folder where to write the files - protected String sourceFolder = "src"; - protected String apiVersion = "1.0.0"; + protected String sourceFolder = ""; + public static final String SRC_BASE_PATH = "srcBasePath"; + public static final String COMPOSER_VENDOR_NAME = "composerVendorName"; + public static final String COMPOSER_PROJECT_NAME = "composerProjectName"; + protected String invokerPackage = "Swagger\\Client"; + protected String composerVendorName = null; + protected String composerProjectName = null; + protected String packagePath = "SwaggerClient-php"; + protected String artifactVersion = null; + protected String srcBasePath = "lib"; + protected String apiVersion = "1.0.0"; + protected String apiDirName = "Api"; + /** * Configures the type of generator. * @@ -46,13 +57,8 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig super(); // set the output folder here - outputFolder = "generated-code/lumen"; - String packagePath = "lumen"; - - // modelPackage = packagePath + "\\lib\\Models"; - // apiPackage = packagePath + "\\lib"; - // // outputFolder = "generated-code" + File.separator + "slim"; - // modelTemplateFiles.put("model.mustache", ".php"); + outputFolder = "lumen"; + String packagePath = ""; /** * Models. You can write model files using the modelTemplateFiles map. @@ -75,7 +81,8 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig // no api files - apiTemplateFiles.clear(); + // apiTemplateFiles.clear(); + apiTemplateFiles.put("api.mustache", ".php"); // embeddedTemplateDir = templateDir = "slim"; @@ -115,43 +122,18 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig * entire object tree available. If the input file has a suffix of `.mustache * it will be processed by the template engine. Otherwise, it will be copied */ - // supportingFiles.add(new SupportingFile("index.mustache", packagePath, "index.php")); - // supportingFiles.add(new SupportingFile("routes.mustache", packagePath, "routes.php")); - - supportingFiles.add(new SupportingFile("composer.json", packagePath, "composer.json")); + supportingFiles.add(new SupportingFile("composer.mustache", packagePath, "composer.json")); supportingFiles.add(new SupportingFile("readme.md", packagePath, "readme.md")); - supportingFiles.add(new SupportingFile("artisan", packagePath, "artisan")); - // supportingFiles.add(new SupportingFile("server.php", packagePath, "server.php")); - - supportingFiles.add(new SupportingFile("bootstrap" + File.separator + "app.php", packagePath + File.separator + "bootstrap", "app.php")); - - supportingFiles.add(new SupportingFile("public" + File.separator + "index.php", packagePath + File.separator + "public", "index.php")); - - supportingFiles.add(new SupportingFile("app" + File.separator + "User.php", packagePath + File.separator + "app", "User.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Console" + File.separator + "Kernel.php", packagePath + File.separator + "app" + File.separator + "Console", "Kernel.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Exceptions" + File.separator + "Handler.php", packagePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php")); - // supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Kernel.php", packagePath + File.separator + "app" + File.separator + "Http", "Kernel.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "routes.mustache", packagePath + File.separator + "app" + File.separator + "Http", "routes.php")); + supportingFiles.add(new SupportingFile("app.php", packagePath + File.separator + "bootstrap", "app.php")); + supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + "public", "index.php")); + supportingFiles.add(new SupportingFile("User.php", packagePath + File.separator + "app", "User.php")); + supportingFiles.add(new SupportingFile("Kernel.php", packagePath + File.separator + "app" + File.separator + "Console", "Kernel.php")); + supportingFiles.add(new SupportingFile("Handler.php", packagePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php")); + supportingFiles.add(new SupportingFile("routes.mustache", packagePath + File.separator + "app" + File.separator + "Http", "routes.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Controllers" + File.separator + "Controller.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Controllers" + File.separator + "ExampleController.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "ExampleController.php")); - // supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Controllers" + File.separator + "Auth" + File.separator + "AuthController.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator + "Auth" + File.separator, "AuthController.php")); - // supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Controllers" + File.separator + "Auth" + File.separator + "PasswordController.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator + "Auth" + File.separator, "PasswordController.php")); + supportingFiles.add(new SupportingFile("Controller.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php")); + supportingFiles.add(new SupportingFile("Authenticate.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Middleware" + File.separator + "Authenticate.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Middleware" + File.separator + "ExampleMiddleware.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "ExampleMiddleware.php")); - // supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Middleware" + File.separator + "RedirectIfAuthenticated.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "RedirectIfAuthenticated.php")); - // supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Middleware" + File.separator + "VerifyCsrfToken.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "VerifyCsrfToken.php")); - - // supportingFiles.add(new SupportingFile("app" + File.separator + "Http" + File.separator + "Requests" + File.separator + "Request.php", packagePath + File.separator + "app" + File.separator + "Http" + File.separator + "Requests" + File.separator, "Request.php")); - - supportingFiles.add(new SupportingFile("app" + File.separator + "Providers" + File.separator + "AppServiceProvider.php", packagePath + File.separator + "app" + File.separator + "Providers", "AppServiceProvider.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Providers" + File.separator + "AuthServiceProvider.php", packagePath + File.separator + "app" + File.separator + "Providers", "AuthServiceProvider.php")); - supportingFiles.add(new SupportingFile("app" + File.separator + "Providers" + File.separator + "EventServiceProvider.php", packagePath + File.separator + "app" + File.separator + "Providers", "EventServiceProvider.php")); - // supportingFiles.add(new SupportingFile("app" + File.separator + "Providers" + File.separator + "RouteServiceProvider.php", packagePath + File.separator + "app" + File.separator + "Providers", "RouteServiceProvider.php")); - - // supportingFiles.add(new SupportingFile("config" + File.separator + "app.php", packagePath + File.separator + "config" + File.separator, "app.php")); - /** * Language Specific Primitives. These types will not trigger imports by * the client generator @@ -188,7 +170,8 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig */ @Override public String apiFileFolder() { - return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar); + return outputFolder + "/app/Http/controllers"; + // return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar); } /** diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Http/Middleware/Authenticate.php b/modules/swagger-codegen/src/main/resources/lumen/Authenticate.php similarity index 100% rename from modules/swagger-codegen/src/main/resources/lumen/app/Http/Middleware/Authenticate.php rename to modules/swagger-codegen/src/main/resources/lumen/Authenticate.php diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/Controller.php b/modules/swagger-codegen/src/main/resources/lumen/Controller.php similarity index 100% rename from modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/Controller.php rename to modules/swagger-codegen/src/main/resources/lumen/Controller.php diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Exceptions/Handler.php b/modules/swagger-codegen/src/main/resources/lumen/Handler.php similarity index 100% rename from modules/swagger-codegen/src/main/resources/lumen/app/Exceptions/Handler.php rename to modules/swagger-codegen/src/main/resources/lumen/Handler.php diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Console/Kernel.php b/modules/swagger-codegen/src/main/resources/lumen/Kernel.php similarity index 100% rename from modules/swagger-codegen/src/main/resources/lumen/app/Console/Kernel.php rename to modules/swagger-codegen/src/main/resources/lumen/Kernel.php diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/User.php b/modules/swagger-codegen/src/main/resources/lumen/User.php similarity index 100% rename from modules/swagger-codegen/src/main/resources/lumen/app/User.php rename to modules/swagger-codegen/src/main/resources/lumen/User.php diff --git a/modules/swagger-codegen/src/main/resources/lumen/api.mustache b/modules/swagger-codegen/src/main/resources/lumen/api.mustache new file mode 100644 index 000000000000..fb735e2fb8ed --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/lumen/api.mustache @@ -0,0 +1,108 @@ +licenseInfo}} + +namespace App\Http\Controllers; + +use Illuminate\Support\Facades\Request; + +{{#operations}}class {{classname}} extends Controller +{ + /** + * Constructor + */ + public function __construct() + { + } + + {{#operation}} + /** + * Operation {{{operationId}}} + * + * {{{summary}}}. + * + {{#pathParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + {{/pathParams}} * + * @return Http response + */ + public function {{operationId}}({{#pathParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/pathParams}}) + { + $input = Request::all(); + + //path params validation + {{#pathParams}} + {{#hasValidation}} + {{#maxLength}} + if (strlen(${{paramName}}]) > {{maxLength}}) { + throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); + } + {{/maxLength}} + {{#minLength}} + if (strlen(${{paramName}}]) < {{minLength}}) { + throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); + } + {{/minLength}} + {{#maximum}} + if (${{paramName}}] > {{maximum}}) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maximum}}.'); + } + {{/maximum}} + {{#minimum}} + if (${{paramName}}] < {{minimum}}) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minimum}}.'); + } + {{/minimum}} + {{#pattern}} + if (!preg_match("{{pattern}}", ${{paramName}}])) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{pattern}}.'); + } + {{/pattern}} + {{/hasValidation}} + {{/pathParams}} + + + //not path params validation + {{#allParams}} + {{^pathParams}} + {{#required}} + if (!isset($input['{{paramName}}'])) { + throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{operationId}}'); + } + {{/required}} + {{#hasValidation}} + {{#maxLength}} + if (strlen($input['{{paramName}}']) > {{maxLength}}) { + throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); + } + {{/maxLength}} + {{#minLength}} + if (strlen($input['{{paramName}}']) < {{minLength}}) { + throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); + } + {{/minLength}} + {{#maximum}} + if ($input['{{paramName}}'] > {{maximum}}) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maximum}}.'); + } + {{/maximum}} + {{#minimum}} + if ($input['{{paramName}}'] < {{minimum}}) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minimum}}.'); + } + {{/minimum}} + {{#pattern}} + if (!preg_match("{{pattern}}", $input['{{paramName}}'])) { + throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{pattern}}.'); + } + {{/pattern}} + {{/hasValidation}} + ${{paramName}} = $input['{{paramName}}']; + + {{/pathParams}} + {{/allParams}} + + return response('How about implementing {{nickname}} as a {{httpMethod}} method ?'); + } + {{/operation}} +} +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/lumen/bootstrap/app.php b/modules/swagger-codegen/src/main/resources/lumen/app.php similarity index 96% rename from modules/swagger-codegen/src/main/resources/lumen/bootstrap/app.php rename to modules/swagger-codegen/src/main/resources/lumen/app.php index 8f1922829982..2811ed03ef94 100644 --- a/modules/swagger-codegen/src/main/resources/lumen/bootstrap/app.php +++ b/modules/swagger-codegen/src/main/resources/lumen/app.php @@ -41,7 +41,7 @@ $app = new Laravel\Lumen\Application( realpath(__DIR__.'/../') ); -// $app->withFacades(); +$app->withFacades(); // $app->withEloquent(); @@ -66,8 +66,6 @@ $app->singleton( App\Console\Kernel::class ); -class_alias('Illuminate\Support\Facades\Request', 'Request'); //to use the Reqesut facade - /* |-------------------------------------------------------------------------- | Register Middleware diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Console/Commands/.gitkeep b/modules/swagger-codegen/src/main/resources/lumen/app/Console/Commands/.gitkeep deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/ExampleController.php b/modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/ExampleController.php deleted file mode 100644 index 60b47ac3a7a7..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/ExampleController.php +++ /dev/null @@ -1,36 +0,0 @@ -licenseInfo}} -{{#apiInfo}}/** - * {{appName}} - * @version {{appVersion}} - */ - -$app->get('/', function () use ($app) { - return $app->version(); -}); - -{{#apis}} -{{#operations}} -{{#operation}} -/** - * {{httpMethod}} {{nickname}} - * Summary: {{summary}} - * Notes: {{notes}} -{{#hasProduces}} * Output-Formats: [{{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}]{{/hasProduces}} - */ -$app->{{httpMethod}}('{{path}}', function({{#pathParams}}${{paramName}}, {{/pathParams}}$null = null) use ($app) { - $input = Request::all(); - - {{#allParams}} - {{#required}} - if (!isset($input['{{paramName}}'])) { - throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{operationId}}'); - } - {{/required}} - {{#hasValidation}} - {{#maxLength}} - if (strlen($input['{{paramName}}']) > {{maxLength}}) { - throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); - } - {{/maxLength}} - {{#minLength}} - if (strlen($input['{{paramName}}']) < {{minLength}}) { - throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); - } - {{/minLength}} - {{#maximum}} - if ($input['{{paramName}}'] > {{maximum}}) { - throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maximum}}.'); - } - {{/maximum}} - {{#minimum}} - if ($input['{{paramName}}'] < {{minimum}}) { - throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minimum}}.'); - } - {{/minimum}} - {{#pattern}} - if (!preg_match("{{pattern}}", $input['{{paramName}}'])) { - throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{pattern}}.'); - } - {{/pattern}} - {{/hasValidation}} - ${{paramName}} = $input['{{paramName}}']; - - {{/allParams}} - return response('How about implementing {{nickname}} as a {{httpMethod}} method ?'); -}); - -{{/operation}} -{{/operations}} -{{/apis}} -{{/apiInfo}} - diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php b/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php deleted file mode 100644 index 2c905bd129a2..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/app/Providers/AppServiceProvider.php +++ /dev/null @@ -1,36 +0,0 @@ -input('api_token')) { - return User::where('api_token', $request->input('api_token'))->first(); - } - }); - } -} diff --git a/modules/swagger-codegen/src/main/resources/lumen/app/Providers/EventServiceProvider.php b/modules/swagger-codegen/src/main/resources/lumen/app/Providers/EventServiceProvider.php deleted file mode 100644 index 1efd71e25720..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/app/Providers/EventServiceProvider.php +++ /dev/null @@ -1,37 +0,0 @@ - [ - 'App\Listeners\EventListener', - ], - ]; -} diff --git a/modules/swagger-codegen/src/main/resources/lumen/composer.json b/modules/swagger-codegen/src/main/resources/lumen/composer.json deleted file mode 100644 index fa92a39def30..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/composer.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "laravel/lumen", - "description": "The Laravel Lumen Framework.", - "keywords": ["framework", "laravel", "lumen"], - "license": "Apache-2.0", - "type": "project", - "require": { - "php": ">=5.5.9", - "laravel/lumen-framework": "5.2.*", - "vlucas/phpdotenv": "~2.2" - }, - "autoload": { - "psr-4": { - "App\\": "app/" - } - } -} diff --git a/modules/swagger-codegen/src/main/resources/lumen/composer.mustache b/modules/swagger-codegen/src/main/resources/lumen/composer.mustache new file mode 100644 index 000000000000..c3ae9fddfbf1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/lumen/composer.mustache @@ -0,0 +1,31 @@ +{ + "name": "{{#composerVendorName}}{{.}}{{/composerVendorName}}{{^composerVendorName}}{{gitUserId}}{{/composerVendorName}}/{{#composerProjectName}}{{.}}{{/composerProjectName}}{{^composerProjectName}}{{gitRepoId}}{{/composerProjectName}}", + {{#artifactVersion}} + "version": "{{artifactVersion}}", + {{/artifactVersion}} + "description": "{{description}}", + "keywords": [ + "swagger", + "php", + "sdk", + "api" + ], + "homepage": "http://swagger.io", + "license": "Apache v2", + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "require": { + "php": ">=5.5.9", + "laravel/lumen-framework": "5.2.*", + "vlucas/phpdotenv": "~2.2" + }, + "autoload": { + "psr-4": { + "App\\": "app/" + } + } +} diff --git a/modules/swagger-codegen/src/main/resources/lumen/public/index.php b/modules/swagger-codegen/src/main/resources/lumen/index.php similarity index 100% rename from modules/swagger-codegen/src/main/resources/lumen/public/index.php rename to modules/swagger-codegen/src/main/resources/lumen/index.php diff --git a/modules/swagger-codegen/src/main/resources/lumen/public/.htaccess b/modules/swagger-codegen/src/main/resources/lumen/public/.htaccess deleted file mode 100644 index 8eb2dd0ddfa5..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/public/.htaccess +++ /dev/null @@ -1,16 +0,0 @@ - - - Options -MultiViews - - - RewriteEngine On - - # Redirect Trailing Slashes If Not A Folder... - RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.*)/$ /$1 [L,R=301] - - # Handle Front Controller... - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^ index.php [L] - diff --git a/modules/swagger-codegen/src/main/resources/lumen/readme.md b/modules/swagger-codegen/src/main/resources/lumen/readme.md index b2507b4e5646..c146781b7ae8 100644 --- a/modules/swagger-codegen/src/main/resources/lumen/readme.md +++ b/modules/swagger-codegen/src/main/resources/lumen/readme.md @@ -1,18 +1,16 @@ -## Lumen PHP Framework +# Swagger generated server -[![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework) -[![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework) -[![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework) -[![Latest Unstable Version](https://poser.pugx.org/laravel/lumen-framework/v/unstable.svg)](https://packagist.org/packages/laravel/lumen-framework) -[![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework) +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the +[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a PHP server. -Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching. +This example uses the [Lumen Framework](http://lumen.laravel.com/). To see how to make this your own, please take a look at the template here: -## Official Documentation +[TEMPLATES](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/slim/) -Documentation for the framework can be found on the [Lumen website](http://lumen.laravel.com/docs). +## Installation & Usage +### Composer -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed. +Using `composer install` to install the framework and dependencies via [Composer](http://getcomposer.org/). diff --git a/modules/swagger-codegen/src/main/resources/lumen/routes.mustache b/modules/swagger-codegen/src/main/resources/lumen/routes.mustache new file mode 100644 index 000000000000..c5f3bdf858ac --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/lumen/routes.mustache @@ -0,0 +1,27 @@ +licenseInfo}} +{{#apiInfo}}/** + * {{appName}} + * @version {{appVersion}} + */ + +$app->get('/', function () use ($app) { + return $app->version(); +}); + +{{#apis}} +{{#operations}} +{{#operation}} +/** + * {{httpMethod}} {{nickname}} + * Summary: {{summary}} + * Notes: {{notes}} +{{#hasProduces}} * Output-Formats: [{{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}]{{/hasProduces}} + */ +$app->{{httpMethod}}('{{path}}', '{{classname}}@{{operationId}}'); +{{/operation}} +{{/operations}} +{{/apis}} +{{/apiInfo}} + diff --git a/modules/swagger-codegen/src/main/resources/lumen/storage/app/.gitignore b/modules/swagger-codegen/src/main/resources/lumen/storage/app/.gitignore deleted file mode 100644 index d6b7ef32c847..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/storage/app/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/modules/swagger-codegen/src/main/resources/lumen/storage/framework/views/.gitignore b/modules/swagger-codegen/src/main/resources/lumen/storage/framework/views/.gitignore deleted file mode 100644 index d6b7ef32c847..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/storage/framework/views/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/modules/swagger-codegen/src/main/resources/lumen/storage/logs/.gitignore b/modules/swagger-codegen/src/main/resources/lumen/storage/logs/.gitignore deleted file mode 100644 index d6b7ef32c847..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/storage/logs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/modules/swagger-codegen/src/main/resources/lumen/tests/ExampleTest.php b/modules/swagger-codegen/src/main/resources/lumen/tests/ExampleTest.php deleted file mode 100644 index 2b206c66173e..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/tests/ExampleTest.php +++ /dev/null @@ -1,20 +0,0 @@ -get('/'); - - $this->assertEquals( - $this->response->getContent(), $this->app->version() - ); - } -} diff --git a/modules/swagger-codegen/src/main/resources/lumen/tests/TestCase.php b/modules/swagger-codegen/src/main/resources/lumen/tests/TestCase.php deleted file mode 100644 index 651d9cbd67f3..000000000000 --- a/modules/swagger-codegen/src/main/resources/lumen/tests/TestCase.php +++ /dev/null @@ -1,14 +0,0 @@ - 543.2) { + throw new \InvalidArgumentException('invalid value for $number when calling FakeApi.testEndpointParameters, must be smaller than or equal to 543.2.'); + } + if ($input['number'] < 32.1) { + throw new \InvalidArgumentException('invalid value for $number when calling FakeApi.testEndpointParameters, must be bigger than or equal to 32.1.'); + } + $number = $input['number']; + + if (!isset($input['double'])) { + throw new \InvalidArgumentException('Missing the required parameter $double when calling testEndpointParameters'); + } + if ($input['double'] > 123.4) { + throw new \InvalidArgumentException('invalid value for $double when calling FakeApi.testEndpointParameters, must be smaller than or equal to 123.4.'); + } + if ($input['double'] < 67.8) { + throw new \InvalidArgumentException('invalid value for $double when calling FakeApi.testEndpointParameters, must be bigger than or equal to 67.8.'); + } + $double = $input['double']; + + if (!isset($input['string'])) { + throw new \InvalidArgumentException('Missing the required parameter $string when calling testEndpointParameters'); + } + if (!preg_match("/[a-z]/i", $input['string'])) { + throw new \InvalidArgumentException('invalid value for $string when calling FakeApi.testEndpointParameters, must conform to the pattern /[a-z]/i.'); + } + $string = $input['string']; + + if (!isset($input['byte'])) { + throw new \InvalidArgumentException('Missing the required parameter $byte when calling testEndpointParameters'); + } + $byte = $input['byte']; + + if ($input['integer'] > 100.0) { + throw new \InvalidArgumentException('invalid value for $integer when calling FakeApi.testEndpointParameters, must be smaller than or equal to 100.0.'); + } + if ($input['integer'] < 10.0) { + throw new \InvalidArgumentException('invalid value for $integer when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.0.'); + } + $integer = $input['integer']; + + if ($input['int32'] > 200.0) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FakeApi.testEndpointParameters, must be smaller than or equal to 200.0.'); + } + if ($input['int32'] < 20.0) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FakeApi.testEndpointParameters, must be bigger than or equal to 20.0.'); + } + $int32 = $input['int32']; + + $int64 = $input['int64']; + + if ($input['float'] > 987.6) { + throw new \InvalidArgumentException('invalid value for $float when calling FakeApi.testEndpointParameters, must be smaller than or equal to 987.6.'); + } + $float = $input['float']; + + $binary = $input['binary']; + + $date = $input['date']; + + $dateTime = $input['dateTime']; + + if (strlen($input['password']) > 64) { + throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be smaller than or equal to 64.'); + } + if (strlen($input['password']) < 10) { + throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.'); + } + $password = $input['password']; + + + return response('How about implementing testEndpointParameters as a POST method ?'); + } +} diff --git a/samples/server/petstore/lumen/app/Http/controllers/PetApi.php b/samples/server/petstore/lumen/app/Http/controllers/PetApi.php new file mode 100644 index 000000000000..dd6a838eaef1 --- /dev/null +++ b/samples/server/petstore/lumen/app/Http/controllers/PetApi.php @@ -0,0 +1,217 @@ + 5.0) { + throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.getOrderById, must be smaller than or equal to 5.0.'); + } + if ($orderId] < 1.0) { + throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.getOrderById, must be bigger than or equal to 1.0.'); + } + + + //not path params validation + + return response('How about implementing getOrderById as a GET method ?'); + } + /** + * Operation placeOrder + * + * Place an order for a pet. + * + * + * @return Http response + */ + public function placeOrder() + { + $input = Request::all(); + + //path params validation + + + //not path params validation + if (!isset($input['body'])) { + throw new \InvalidArgumentException('Missing the required parameter $body when calling placeOrder'); + } + $body = $input['body']; + + + return response('How about implementing placeOrder as a POST method ?'); + } +} diff --git a/samples/server/petstore/lumen/app/Http/controllers/UserApi.php b/samples/server/petstore/lumen/app/Http/controllers/UserApi.php new file mode 100644 index 000000000000..f9ade75e98a4 --- /dev/null +++ b/samples/server/petstore/lumen/app/Http/controllers/UserApi.php @@ -0,0 +1,221 @@ +get('/', function () use ($app) { + return $app->version(); +}); + +/** + * POST testEndpointParameters + * Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * Output-Formats: [application/xml; charset=utf-8, application/json; charset=utf-8] + */ +$app->POST('/fake', 'FakeApi@testEndpointParameters'); +/** + * POST addPet + * Summary: Add a new pet to the store + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/pet', 'PetApi@addPet'); +/** + * DELETE deletePet + * Summary: Deletes a pet + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->DELETE('/pet/{petId}', 'PetApi@deletePet'); +/** + * GET findPetsByStatus + * Summary: Finds Pets by status + * Notes: Multiple status values can be provided with comma separated strings + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/pet/findByStatus', 'PetApi@findPetsByStatus'); +/** + * GET findPetsByTags + * Summary: Finds Pets by tags + * Notes: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/pet/findByTags', 'PetApi@findPetsByTags'); +/** + * GET getPetById + * Summary: Find pet by ID + * Notes: Returns a single pet + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/pet/{petId}', 'PetApi@getPetById'); +/** + * PUT updatePet + * Summary: Update an existing pet + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->PUT('/pet', 'PetApi@updatePet'); +/** + * POST updatePetWithForm + * Summary: Updates a pet in the store with form data + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/pet/{petId}', 'PetApi@updatePetWithForm'); +/** + * POST uploadFile + * Summary: uploads an image + * Notes: + * Output-Formats: [application/json] + */ +$app->POST('/pet/{petId}/uploadImage', 'PetApi@uploadFile'); +/** + * DELETE deleteOrder + * Summary: Delete purchase order by ID + * Notes: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * Output-Formats: [application/xml, application/json] + */ +$app->DELETE('/store/order/{orderId}', 'StoreApi@deleteOrder'); +/** + * GET getInventory + * Summary: Returns pet inventories by status + * Notes: Returns a map of status codes to quantities + * Output-Formats: [application/json] + */ +$app->GET('/store/inventory', 'StoreApi@getInventory'); +/** + * GET getOrderById + * Summary: Find purchase order by ID + * Notes: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/store/order/{orderId}', 'StoreApi@getOrderById'); +/** + * POST placeOrder + * Summary: Place an order for a pet + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/store/order', 'StoreApi@placeOrder'); +/** + * POST createUser + * Summary: Create user + * Notes: This can only be done by the logged in user. + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/user', 'UserApi@createUser'); +/** + * POST createUsersWithArrayInput + * Summary: Creates list of users with given input array + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/user/createWithArray', 'UserApi@createUsersWithArrayInput'); +/** + * POST createUsersWithListInput + * Summary: Creates list of users with given input array + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->POST('/user/createWithList', 'UserApi@createUsersWithListInput'); +/** + * DELETE deleteUser + * Summary: Delete user + * Notes: This can only be done by the logged in user. + * Output-Formats: [application/xml, application/json] + */ +$app->DELETE('/user/{username}', 'UserApi@deleteUser'); +/** + * GET getUserByName + * Summary: Get user by user name + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/user/{username}', 'UserApi@getUserByName'); +/** + * GET loginUser + * Summary: Logs user into the system + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/user/login', 'UserApi@loginUser'); +/** + * GET logoutUser + * Summary: Logs out current logged in user session + * Notes: + * Output-Formats: [application/xml, application/json] + */ +$app->GET('/user/logout', 'UserApi@logoutUser'); +/** + * PUT updateUser + * Summary: Updated user + * Notes: This can only be done by the logged in user. + * Output-Formats: [application/xml, application/json] + */ +$app->PUT('/user/{username}', 'UserApi@updateUser'); + diff --git a/samples/server/petstore/lumen/lumen/app/User.php b/samples/server/petstore/lumen/app/User.php similarity index 100% rename from samples/server/petstore/lumen/lumen/app/User.php rename to samples/server/petstore/lumen/app/User.php diff --git a/samples/server/petstore/lumen/lumen/bootstrap/app.php b/samples/server/petstore/lumen/bootstrap/app.php similarity index 96% rename from samples/server/petstore/lumen/lumen/bootstrap/app.php rename to samples/server/petstore/lumen/bootstrap/app.php index 8f1922829982..2811ed03ef94 100644 --- a/samples/server/petstore/lumen/lumen/bootstrap/app.php +++ b/samples/server/petstore/lumen/bootstrap/app.php @@ -41,7 +41,7 @@ $app = new Laravel\Lumen\Application( realpath(__DIR__.'/../') ); -// $app->withFacades(); +$app->withFacades(); // $app->withEloquent(); @@ -66,8 +66,6 @@ $app->singleton( App\Console\Kernel::class ); -class_alias('Illuminate\Support\Facades\Request', 'Request'); //to use the Reqesut facade - /* |-------------------------------------------------------------------------- | Register Middleware diff --git a/samples/server/petstore/lumen/composer.json b/samples/server/petstore/lumen/composer.json new file mode 100644 index 000000000000..55559dfaac90 --- /dev/null +++ b/samples/server/petstore/lumen/composer.json @@ -0,0 +1,28 @@ +{ + "name": "GIT_USER_ID/GIT_REPO_ID", + "description": "", + "keywords": [ + "swagger", + "php", + "sdk", + "api" + ], + "homepage": "http://swagger.io", + "license": "Apache v2", + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "require": { + "php": ">=5.5.9", + "laravel/lumen-framework": "5.2.*", + "vlucas/phpdotenv": "~2.2" + }, + "autoload": { + "psr-4": { + "App\\": "app/" + } + } +} diff --git a/samples/server/petstore/lumen/lumen/app/Http/Controllers/ExampleController.php b/samples/server/petstore/lumen/lumen/app/Http/Controllers/ExampleController.php deleted file mode 100644 index 60b47ac3a7a7..000000000000 --- a/samples/server/petstore/lumen/lumen/app/Http/Controllers/ExampleController.php +++ /dev/null @@ -1,36 +0,0 @@ -get('/', function () use ($app) { - return $app->version(); -}); - -/** - * POST testEndpointParameters - * Summary: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 - * Notes: Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 - * Output-Formats: [application/xml; charset=utf-8, application/json; charset=utf-8] - */ -$app->POST('/fake', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['number'])) { - throw new \InvalidArgumentException('Missing the required parameter $number when calling testEndpointParameters'); - } - if ($input['number'] > 543.2) { - throw new \InvalidArgumentException('invalid value for $number when calling FakeApi.testEndpointParameters, must be smaller than or equal to 543.2.'); - } - if ($input['number'] < 32.1) { - throw new \InvalidArgumentException('invalid value for $number when calling FakeApi.testEndpointParameters, must be bigger than or equal to 32.1.'); - } - $number = $input['number']; - - if (!isset($input['double'])) { - throw new \InvalidArgumentException('Missing the required parameter $double when calling testEndpointParameters'); - } - if ($input['double'] > 123.4) { - throw new \InvalidArgumentException('invalid value for $double when calling FakeApi.testEndpointParameters, must be smaller than or equal to 123.4.'); - } - if ($input['double'] < 67.8) { - throw new \InvalidArgumentException('invalid value for $double when calling FakeApi.testEndpointParameters, must be bigger than or equal to 67.8.'); - } - $double = $input['double']; - - if (!isset($input['string'])) { - throw new \InvalidArgumentException('Missing the required parameter $string when calling testEndpointParameters'); - } - if (!preg_match("/[a-z]/i", $input['string'])) { - throw new \InvalidArgumentException('invalid value for $string when calling FakeApi.testEndpointParameters, must conform to the pattern /[a-z]/i.'); - } - $string = $input['string']; - - if (!isset($input['byte'])) { - throw new \InvalidArgumentException('Missing the required parameter $byte when calling testEndpointParameters'); - } - $byte = $input['byte']; - - if ($input['integer'] > 100.0) { - throw new \InvalidArgumentException('invalid value for $integer when calling FakeApi.testEndpointParameters, must be smaller than or equal to 100.0.'); - } - if ($input['integer'] < 10.0) { - throw new \InvalidArgumentException('invalid value for $integer when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.0.'); - } - $integer = $input['integer']; - - if ($input['int32'] > 200.0) { - throw new \InvalidArgumentException('invalid value for $int32 when calling FakeApi.testEndpointParameters, must be smaller than or equal to 200.0.'); - } - if ($input['int32'] < 20.0) { - throw new \InvalidArgumentException('invalid value for $int32 when calling FakeApi.testEndpointParameters, must be bigger than or equal to 20.0.'); - } - $int32 = $input['int32']; - - $int64 = $input['int64']; - - if ($input['float'] > 987.6) { - throw new \InvalidArgumentException('invalid value for $float when calling FakeApi.testEndpointParameters, must be smaller than or equal to 987.6.'); - } - $float = $input['float']; - - $binary = $input['binary']; - - $date = $input['date']; - - $dateTime = $input['dateTime']; - - if (strlen($input['password']) > 64) { - throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be smaller than or equal to 64.'); - } - if (strlen($input['password']) < 10) { - throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.'); - } - $password = $input['password']; - - return response('How about implementing testEndpointParameters as a POST method ?'); -}); - -/** - * POST addPet - * Summary: Add a new pet to the store - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->POST('/pet', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling addPet'); - } - $body = $input['body']; - - return response('How about implementing addPet as a POST method ?'); -}); - -/** - * DELETE deletePet - * Summary: Deletes a pet - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->DELETE('/pet/{petId}', function($petId, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['petId'])) { - throw new \InvalidArgumentException('Missing the required parameter $petId when calling deletePet'); - } - $petId = $input['petId']; - - $apiKey = $input['apiKey']; - - return response('How about implementing deletePet as a DELETE method ?'); -}); - -/** - * GET findPetsByStatus - * Summary: Finds Pets by status - * Notes: Multiple status values can be provided with comma separated strings - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/pet/findByStatus', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['status'])) { - throw new \InvalidArgumentException('Missing the required parameter $status when calling findPetsByStatus'); - } - $status = $input['status']; - - return response('How about implementing findPetsByStatus as a GET method ?'); -}); - -/** - * GET findPetsByTags - * Summary: Finds Pets by tags - * Notes: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/pet/findByTags', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['tags'])) { - throw new \InvalidArgumentException('Missing the required parameter $tags when calling findPetsByTags'); - } - $tags = $input['tags']; - - return response('How about implementing findPetsByTags as a GET method ?'); -}); - -/** - * GET getPetById - * Summary: Find pet by ID - * Notes: Returns a single pet - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/pet/{petId}', function($petId, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['petId'])) { - throw new \InvalidArgumentException('Missing the required parameter $petId when calling getPetById'); - } - $petId = $input['petId']; - - return response('How about implementing getPetById as a GET method ?'); -}); - -/** - * PUT updatePet - * Summary: Update an existing pet - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->PUT('/pet', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling updatePet'); - } - $body = $input['body']; - - return response('How about implementing updatePet as a PUT method ?'); -}); - -/** - * POST updatePetWithForm - * Summary: Updates a pet in the store with form data - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->POST('/pet/{petId}', function($petId, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['petId'])) { - throw new \InvalidArgumentException('Missing the required parameter $petId when calling updatePetWithForm'); - } - $petId = $input['petId']; - - $name = $input['name']; - - $status = $input['status']; - - return response('How about implementing updatePetWithForm as a POST method ?'); -}); - -/** - * POST uploadFile - * Summary: uploads an image - * Notes: - * Output-Formats: [application/json] - */ -$app->POST('/pet/{petId}/uploadImage', function($petId, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['petId'])) { - throw new \InvalidArgumentException('Missing the required parameter $petId when calling uploadFile'); - } - $petId = $input['petId']; - - $additionalMetadata = $input['additionalMetadata']; - - $file = $input['file']; - - return response('How about implementing uploadFile as a POST method ?'); -}); - -/** - * DELETE deleteOrder - * Summary: Delete purchase order by ID - * Notes: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * Output-Formats: [application/xml, application/json] - */ -$app->DELETE('/store/order/{orderId}', function($orderId, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['orderId'])) { - throw new \InvalidArgumentException('Missing the required parameter $orderId when calling deleteOrder'); - } - if ($input['orderId'] < 1.0) { - throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.deleteOrder, must be bigger than or equal to 1.0.'); - } - $orderId = $input['orderId']; - - return response('How about implementing deleteOrder as a DELETE method ?'); -}); - -/** - * GET getInventory - * Summary: Returns pet inventories by status - * Notes: Returns a map of status codes to quantities - * Output-Formats: [application/json] - */ -$app->GET('/store/inventory', function($null = null) use ($app) { - $input = Request::all(); - - return response('How about implementing getInventory as a GET method ?'); -}); - -/** - * GET getOrderById - * Summary: Find purchase order by ID - * Notes: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/store/order/{orderId}', function($orderId, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['orderId'])) { - throw new \InvalidArgumentException('Missing the required parameter $orderId when calling getOrderById'); - } - if ($input['orderId'] > 5.0) { - throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.getOrderById, must be smaller than or equal to 5.0.'); - } - if ($input['orderId'] < 1.0) { - throw new \InvalidArgumentException('invalid value for $orderId when calling StoreApi.getOrderById, must be bigger than or equal to 1.0.'); - } - $orderId = $input['orderId']; - - return response('How about implementing getOrderById as a GET method ?'); -}); - -/** - * POST placeOrder - * Summary: Place an order for a pet - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->POST('/store/order', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling placeOrder'); - } - $body = $input['body']; - - return response('How about implementing placeOrder as a POST method ?'); -}); - -/** - * POST createUser - * Summary: Create user - * Notes: This can only be done by the logged in user. - * Output-Formats: [application/xml, application/json] - */ -$app->POST('/user', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling createUser'); - } - $body = $input['body']; - - return response('How about implementing createUser as a POST method ?'); -}); - -/** - * POST createUsersWithArrayInput - * Summary: Creates list of users with given input array - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->POST('/user/createWithArray', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling createUsersWithArrayInput'); - } - $body = $input['body']; - - return response('How about implementing createUsersWithArrayInput as a POST method ?'); -}); - -/** - * POST createUsersWithListInput - * Summary: Creates list of users with given input array - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->POST('/user/createWithList', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling createUsersWithListInput'); - } - $body = $input['body']; - - return response('How about implementing createUsersWithListInput as a POST method ?'); -}); - -/** - * DELETE deleteUser - * Summary: Delete user - * Notes: This can only be done by the logged in user. - * Output-Formats: [application/xml, application/json] - */ -$app->DELETE('/user/{username}', function($username, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['username'])) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); - } - $username = $input['username']; - - return response('How about implementing deleteUser as a DELETE method ?'); -}); - -/** - * GET getUserByName - * Summary: Get user by user name - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/user/{username}', function($username, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['username'])) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); - } - $username = $input['username']; - - return response('How about implementing getUserByName as a GET method ?'); -}); - -/** - * GET loginUser - * Summary: Logs user into the system - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/user/login', function($null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['username'])) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling loginUser'); - } - $username = $input['username']; - - if (!isset($input['password'])) { - throw new \InvalidArgumentException('Missing the required parameter $password when calling loginUser'); - } - $password = $input['password']; - - return response('How about implementing loginUser as a GET method ?'); -}); - -/** - * GET logoutUser - * Summary: Logs out current logged in user session - * Notes: - * Output-Formats: [application/xml, application/json] - */ -$app->GET('/user/logout', function($null = null) use ($app) { - $input = Request::all(); - - return response('How about implementing logoutUser as a GET method ?'); -}); - -/** - * PUT updateUser - * Summary: Updated user - * Notes: This can only be done by the logged in user. - * Output-Formats: [application/xml, application/json] - */ -$app->PUT('/user/{username}', function($username, $null = null) use ($app) { - $input = Request::all(); - - if (!isset($input['username'])) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); - } - $username = $input['username']; - - if (!isset($input['body'])) { - throw new \InvalidArgumentException('Missing the required parameter $body when calling updateUser'); - } - $body = $input['body']; - - return response('How about implementing updateUser as a PUT method ?'); -}); - - diff --git a/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php b/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php deleted file mode 100644 index 2c905bd129a2..000000000000 --- a/samples/server/petstore/lumen/lumen/app/Providers/AppServiceProvider.php +++ /dev/null @@ -1,36 +0,0 @@ -input('api_token')) { - return User::where('api_token', $request->input('api_token'))->first(); - } - }); - } -} diff --git a/samples/server/petstore/lumen/lumen/app/Providers/EventServiceProvider.php b/samples/server/petstore/lumen/lumen/app/Providers/EventServiceProvider.php deleted file mode 100644 index 1efd71e25720..000000000000 --- a/samples/server/petstore/lumen/lumen/app/Providers/EventServiceProvider.php +++ /dev/null @@ -1,37 +0,0 @@ - [ - 'App\Listeners\EventListener', - ], - ]; -} diff --git a/samples/server/petstore/lumen/lumen/artisan b/samples/server/petstore/lumen/lumen/artisan deleted file mode 100644 index 6a9d095aeae0..000000000000 --- a/samples/server/petstore/lumen/lumen/artisan +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env php -make( - 'Illuminate\Contracts\Console\Kernel' -); - -exit($kernel->handle(new ArgvInput, new ConsoleOutput)); diff --git a/samples/server/petstore/lumen/lumen/composer.json b/samples/server/petstore/lumen/lumen/composer.json deleted file mode 100644 index fa92a39def30..000000000000 --- a/samples/server/petstore/lumen/lumen/composer.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "laravel/lumen", - "description": "The Laravel Lumen Framework.", - "keywords": ["framework", "laravel", "lumen"], - "license": "Apache-2.0", - "type": "project", - "require": { - "php": ">=5.5.9", - "laravel/lumen-framework": "5.2.*", - "vlucas/phpdotenv": "~2.2" - }, - "autoload": { - "psr-4": { - "App\\": "app/" - } - } -} diff --git a/samples/server/petstore/lumen/lumen/readme.md b/samples/server/petstore/lumen/lumen/readme.md deleted file mode 100644 index b2507b4e5646..000000000000 --- a/samples/server/petstore/lumen/lumen/readme.md +++ /dev/null @@ -1,18 +0,0 @@ -## Lumen PHP Framework - -[![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework) -[![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework) -[![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework) -[![Latest Unstable Version](https://poser.pugx.org/laravel/lumen-framework/v/unstable.svg)](https://packagist.org/packages/laravel/lumen-framework) -[![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework) - -Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching. - -## Official Documentation - -Documentation for the framework can be found on the [Lumen website](http://lumen.laravel.com/docs). - -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed. - diff --git a/samples/server/petstore/lumen/lumen/public/index.php b/samples/server/petstore/lumen/public/index.php similarity index 100% rename from samples/server/petstore/lumen/lumen/public/index.php rename to samples/server/petstore/lumen/public/index.php diff --git a/samples/server/petstore/lumen/readme.md b/samples/server/petstore/lumen/readme.md new file mode 100644 index 000000000000..c146781b7ae8 --- /dev/null +++ b/samples/server/petstore/lumen/readme.md @@ -0,0 +1,16 @@ +# Swagger generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the +[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a PHP server. + +This example uses the [Lumen Framework](http://lumen.laravel.com/). To see how to make this your own, please take a look at the template here: + +[TEMPLATES](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/slim/) + +## Installation & Usage +### Composer + +Using `composer install` to install the framework and dependencies via [Composer](http://getcomposer.org/). +