forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (PHP LARAVEL) 8417: initial PHP-laravel codegen integration (Ope…
…nAPITools#574) * feat (PHP LARAVEL) 8417: initial PHP-laravel codegen integration * feat (PHP LARAVEL) 8417: code review adjustments * feat (PHP LARAVEL) 8417: fix typos; add missing files; adjust readme for those unfamilar with laravel to get started quickly * feat (PHP LARAVEL) 8417: add sample petstore server * feat (PHP LARAVEL) 8417: adjust route service provdider and model generation
- Loading branch information
1 parent
bbe7b9a
commit 94a69ac
Showing
205 changed files
with
8,380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT="$0" | ||
echo "# START SCRIPT: $SCRIPT" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
# Make sure that the working directory is the root dir | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
cd "${SCRIPT_DIR}/../" | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=`dirname "$SCRIPT"`/.. | ||
APP_DIR=`cd "${APP_DIR}"; pwd` | ||
fi | ||
|
||
# Make sure that we are regenerating the sample by removing any existing target directory | ||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-laravel" | ||
if [ -d "$TARGET_DIR" ]; then | ||
rm -rf $TARGET_DIR | ||
fi | ||
|
||
executable="$SCRIPT_DIR/../../modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn clean package | ||
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 $SCRIPT_DIR/../../modules/openapi-generator/src/main/resources/php-laravel -i $SCRIPT_DIR/../../modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-laravel -o $TARGET_DIR $@" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
echo "# START SCRIPT: $SCRIPT" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=`dirname "$SCRIPT"`/.. | ||
APP_DIR=`cd "${APP_DIR}"; pwd` | ||
fi | ||
|
||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn -B clean package | ||
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/openapi-generator/src/main/resources/php-laravel -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php-laravel -o samples/server/petstore/php-laravel $@" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
285 changes: 285 additions & 0 deletions
285
...i-generator/src/main/java/org/openapitools/codegen/languages/PhpLaravelServerCodegen.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
modules/openapi-generator/src/main/resources/php-laravel/.env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
APP_NAME=Laravel | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_URL=http://localhost | ||
|
||
LOG_CHANNEL=stack | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=homestead | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=file | ||
SESSION_DRIVER=file | ||
SESSION_LIFETIME=120 | ||
QUEUE_DRIVER=sync | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_DRIVER=smtp | ||
MAIL_HOST=smtp.mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_APP_KEY= | ||
PUSHER_APP_SECRET= | ||
PUSHER_APP_CLUSTER=mt1 | ||
|
||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | ||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" |
23 changes: 23 additions & 0 deletions
23
modules/openapi-generator/src/main/resources/php-laravel/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OpenAPI generated server | ||
|
||
## Overview | ||
This server was generated by the [openapi-generator](https://github.com/openapitools/openapi-generator) 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 [laravel Framework](http://laravel.com/). To see how to make this your own, please take a look at the template here: | ||
|
||
## Installation & Usage | ||
### Composer | ||
|
||
Using `composer install` to install the framework and dependencies via [Composer](http://getcomposer.org/). | ||
|
||
### post installation steps | ||
|
||
Change into application folder and execute following commands to get started: | ||
|
||
```sh | ||
cp .env.example .env | ||
php artisan key:generate | ||
php artisan serve | ||
``` |
128 changes: 128 additions & 0 deletions
128
modules/openapi-generator/src/main/resources/php-laravel/api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
{{>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}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { | ||
throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.'); | ||
} | ||
{{/maximum}} | ||
{{#minimum}} | ||
if (${{paramName}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { | ||
throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{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}} | ||
{{#maxItems}} | ||
if (count(${{paramName}}) > {{maxItems}}) { | ||
throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.'); | ||
} | ||
{{/maxItems}} | ||
{{#minItems}} | ||
if (count(${{paramName}}) < {{minItems}}) { | ||
throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.'); | ||
} | ||
{{/minItems}} | ||
{{/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}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { | ||
throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.'); | ||
} | ||
{{/maximum}} | ||
{{#minimum}} | ||
if ($input['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { | ||
throw new \InvalidArgumentException('invalid value for ${{paramName}} when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{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}} | ||
{{#maxItems}} | ||
if (count($input['{{paramName}}']) > {{maxItems}}) { | ||
throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.'); | ||
} | ||
{{/maxItems}} | ||
{{#minItems}} | ||
if (count($input['{{paramName}}']) < {{minItems}}) { | ||
throw new \InvalidArgumentException('invalid length for ${{paramName}} when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.'); | ||
} | ||
{{/minItems}} | ||
{{/hasValidation}} | ||
${{paramName}} = $input['{{paramName}}']; | ||
|
||
{{/pathParams}} | ||
{{/allParams}} | ||
|
||
return response('How about implementing {{nickname}} as a {{httpMethod}} method ?'); | ||
} | ||
{{/operation}} | ||
} | ||
{{/operations}} |
42 changes: 42 additions & 0 deletions
42
modules/openapi-generator/src/main/resources/php-laravel/app/Console/Kernel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||
|
||
class Kernel extends ConsoleKernel | ||
{ | ||
/** | ||
* The Artisan commands provided by your application. | ||
* | ||
* @var array | ||
*/ | ||
protected $commands = [ | ||
// | ||
]; | ||
|
||
/** | ||
* Define the application's command schedule. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | ||
* @return void | ||
*/ | ||
protected function schedule(Schedule $schedule) | ||
{ | ||
// $schedule->command('inspire') | ||
// ->hourly(); | ||
} | ||
|
||
/** | ||
* Register the commands for the application. | ||
* | ||
* @return void | ||
*/ | ||
protected function commands() | ||
{ | ||
$this->load(__DIR__.'/Commands'); | ||
|
||
require base_path('routes/console.php'); | ||
} | ||
} |
Oops, something went wrong.