-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2658 from wing328/php_lumen
[PHP] Add PHP Lumen generator
- Loading branch information
Showing
47 changed files
with
1,730 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
|
||
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/swagger-codegen-cli/target/swagger-codegen-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 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" | ||
|
||
java $JAVA_OPTS -jar $executable $ags |
235 changes: 235 additions & 0 deletions
235
modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LumenServerCodegen.java
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,235 @@ | ||
package io.swagger.codegen.languages; | ||
|
||
import io.swagger.codegen.*; | ||
import io.swagger.models.properties.*; | ||
|
||
import java.util.*; | ||
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"; | ||
|
||
/** | ||
* Configures the type of generator. | ||
* | ||
* @return the CodegenType for this generator | ||
* @see io.swagger.codegen.CodegenType | ||
*/ | ||
public CodegenType getTag() { | ||
return CodegenType.CLIENT; | ||
} | ||
|
||
/** | ||
* Configures a friendly name for the generator. This will be used by the generator | ||
* to select the library with the -l flag. | ||
* | ||
* @return the friendly name for the generator | ||
*/ | ||
public String getName() { | ||
return "lumen"; | ||
} | ||
|
||
/** | ||
* Returns human-friendly help for the generator. Provide the consumer with help | ||
* tips, parameters here | ||
* | ||
* @return A string value for the help message | ||
*/ | ||
public String getHelp() { | ||
return "Generates a LumenServerCodegen client library."; | ||
} | ||
|
||
public LumenServerCodegen() { | ||
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"); | ||
|
||
/** | ||
* Models. You can write model files using the modelTemplateFiles map. | ||
* if you want to create one template for file, you can do so here. | ||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with | ||
* a different extension | ||
*/ | ||
// modelTemplateFiles.put( | ||
// "model.mustache", // the template to use | ||
// ".sample"); // the extension for each file to write | ||
|
||
/** | ||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map. | ||
* as with models, add multiple entries with different extensions for multiple files per | ||
* class | ||
*/ | ||
// apiTemplateFiles.put( | ||
// "api.mustache", // the template to use | ||
// ".sample"); // the extension for each file to write | ||
|
||
|
||
// no api files | ||
apiTemplateFiles.clear(); | ||
|
||
// embeddedTemplateDir = templateDir = "slim"; | ||
|
||
/** | ||
* Template Location. This is the location which templates will be read from. The generator | ||
* will use the resource stream to attempt to read the templates. | ||
*/ | ||
templateDir = "lumen"; | ||
|
||
/** | ||
* Api Package. Optional, if needed, this can be used in templates | ||
*/ | ||
apiPackage = "io.swagger.client.api"; | ||
|
||
/** | ||
* Model Package. Optional, if needed, this can be used in templates | ||
*/ | ||
modelPackage = "io.swagger.client.model"; | ||
|
||
/** | ||
* Reserved words. Override this with reserved words specific to your language | ||
*/ | ||
reservedWords = new HashSet<String> ( | ||
Arrays.asList( | ||
"sample1", // replace with static values | ||
"sample2") | ||
); | ||
|
||
/** | ||
* Additional Properties. These values can be passed to the templates and | ||
* are available in models, apis, and supporting files | ||
*/ | ||
additionalProperties.put("apiVersion", apiVersion); | ||
|
||
/** | ||
* Supporting Files. You can write single files for the generator with the | ||
* 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("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" + 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("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 | ||
*/ | ||
languageSpecificPrimitives = new HashSet<String>( | ||
Arrays.asList( | ||
"Type1", // replace these with your types | ||
"Type2") | ||
); | ||
} | ||
|
||
/** | ||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping | ||
* those terms here. This logic is only called if a variable matches the reseved words | ||
* | ||
* @return the escaped term | ||
*/ | ||
@Override | ||
public String escapeReservedWord(String name) { | ||
return "_" + name; // add an underscore to the name | ||
} | ||
|
||
/** | ||
* Location to write model files. You can use the modelPackage() as defined when the class is | ||
* instantiated | ||
*/ | ||
public String modelFileFolder() { | ||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar); | ||
} | ||
|
||
/** | ||
* Location to write api files. You can use the apiPackage() as defined when the class is | ||
* instantiated | ||
*/ | ||
@Override | ||
public String apiFileFolder() { | ||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar); | ||
} | ||
|
||
/** | ||
* Optional - type declaration. This is a String which is used by the templates to instantiate your | ||
* types. There is typically special handling for different property types | ||
* | ||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates | ||
*/ | ||
@Override | ||
public String getTypeDeclaration(Property p) { | ||
if(p instanceof ArrayProperty) { | ||
ArrayProperty ap = (ArrayProperty) p; | ||
Property inner = ap.getItems(); | ||
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]"; | ||
} | ||
else if (p instanceof MapProperty) { | ||
MapProperty mp = (MapProperty) p; | ||
Property inner = mp.getAdditionalProperties(); | ||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]"; | ||
} | ||
return super.getTypeDeclaration(p); | ||
} | ||
|
||
/** | ||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into | ||
* either language specific types via `typeMapping` or into complex models if there is not a mapping. | ||
* | ||
* @return a string value of the type or complex model for this property | ||
* @see io.swagger.models.properties.Property | ||
*/ | ||
@Override | ||
public String getSwaggerType(Property p) { | ||
String swaggerType = super.getSwaggerType(p); | ||
String type = null; | ||
if(typeMapping.containsKey(swaggerType)) { | ||
type = typeMapping.get(swaggerType); | ||
if(languageSpecificPrimitives.contains(type)) | ||
return toModelName(type); | ||
} | ||
else | ||
type = swaggerType; | ||
return toModelName(type); | ||
} | ||
} |
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
Empty file.
29 changes: 29 additions & 0 deletions
29
modules/swagger-codegen/src/main/resources/lumen/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,29 @@ | ||
<?php | ||
|
||
namespace App\Console; | ||
|
||
use Illuminate\Console\Scheduling\Schedule; | ||
use Laravel\Lumen\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) | ||
{ | ||
// | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
modules/swagger-codegen/src/main/resources/lumen/app/Exceptions/Handler.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,50 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Validation\ValidationException; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; | ||
|
||
class Handler extends ExceptionHandler | ||
{ | ||
/** | ||
* A list of the exception types that should not be reported. | ||
* | ||
* @var array | ||
*/ | ||
protected $dontReport = [ | ||
AuthorizationException::class, | ||
HttpException::class, | ||
ModelNotFoundException::class, | ||
ValidationException::class, | ||
]; | ||
|
||
/** | ||
* Report or log an exception. | ||
* | ||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. | ||
* | ||
* @param \Exception $e | ||
* @return void | ||
*/ | ||
public function report(Exception $e) | ||
{ | ||
parent::report($e); | ||
} | ||
|
||
/** | ||
* Render an exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Exception $e | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request, Exception $e) | ||
{ | ||
return parent::render($request, $e); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/Controller.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,10 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Laravel\Lumen\Routing\Controller as BaseController; | ||
|
||
class Controller extends BaseController | ||
{ | ||
// | ||
} |
18 changes: 18 additions & 0 deletions
18
modules/swagger-codegen/src/main/resources/lumen/app/Http/Controllers/ExampleController.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,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
class ExampleController extends Controller | ||
{ | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
// | ||
} |
Oops, something went wrong.