Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import java.util.Map;
import java.util.TreeMap;

public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig {

// source folder where to write the files
protected String sourceFolder = "";
public class LumenServerCodegen extends AbstractPhpCodegen
{
@SuppressWarnings("hiding")
protected String apiVersion = "1.0.0";

/**
Expand Down Expand Up @@ -43,47 +42,19 @@ public String getName() {
* @return A string value for the help message
*/
public String getHelp() {
return "Generates a LumenServerCodegen client library.";
return "Generates a LumenServerCodegen server library.";
}

public LumenServerCodegen() {
super();

// set the output folder here
outputFolder = "lumen";
String packagePath = "";

/**
* 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();
apiTemplateFiles.put("api.mustache", ".php");

// embeddedTemplateDir = templateDir = "slim";
embeddedTemplateDir = templateDir = "lumen";

/**
* 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.
* packPath
*/
templateDir = "lumen";
invokerPackage = "lumen";
packagePath = "";

/**
* Api Package. Optional, if needed, this can be used in templates
Expand All @@ -95,14 +66,11 @@ public LumenServerCodegen() {
*/
modelPackage = "models";

/**
* Reserved words. Override this with reserved words specific to your language
*/
reservedWords = new HashSet<String> (
Arrays.asList(
"sample1", // replace with static values
"sample2")
);
// template files want to be ignored
modelTemplateFiles.clear();
apiTestTemplateFiles.clear();
apiDocTemplateFiles.clear();
modelDocTemplateFiles.clear();

/**
* Additional Properties. These values can be passed to the templates and
Expand All @@ -115,55 +83,18 @@ public LumenServerCodegen() {
* 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("composer.mustache", packagePath, "composer.json"));
supportingFiles.add(new SupportingFile("readme.md", packagePath, "readme.md"));
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("composer.mustache", packagePath + File.separator + srcBasePath, "composer.json"));
supportingFiles.add(new SupportingFile("readme.md", packagePath + File.separator + srcBasePath, "readme.md"));
supportingFiles.add(new SupportingFile("app.php", packagePath + File.separator + srcBasePath + File.separator + "bootstrap", "app.php"));
supportingFiles.add(new SupportingFile("index.php", packagePath + File.separator + srcBasePath + File.separator + "public", "index.php"));
supportingFiles.add(new SupportingFile("User.php", packagePath + File.separator + srcBasePath + File.separator + "app", "User.php"));
supportingFiles.add(new SupportingFile("Kernel.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Console", "Kernel.php"));
supportingFiles.add(new SupportingFile("Handler.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Exceptions", "Handler.php"));
supportingFiles.add(new SupportingFile("routes.mustache", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http", "routes.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("Controller.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Controllers" + File.separator, "Controller.php"));
supportingFiles.add(new SupportingFile("Authenticate.php", packagePath + File.separator + srcBasePath + File.separator + "app" + File.separator + "Http" + File.separator + "Middleware" + File.separator, "Authenticate.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 + "/" + 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 + "/" + apiPackage().replace('.', File.separatorChar);//"/app/Http/controllers";
}

// override with any special post-processing
Expand All @@ -185,57 +116,4 @@ public int compare(CodegenOperation lhs, CodegenOperation rhs) {

return objs;
}
/**
* 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);
}

@Override
public String escapeQuotationMark(String input) {
// remove ' to avoid code injection
return input.replace("'", "");
}

@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ protected void setExpectations() {
new Expectations(clientCodegen) {{
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(LumenServerOptionsProvider.SORT_PARAMS_VALUE));
times = 1;
clientCodegen.setParameterNamingConvention(LumenServerOptionsProvider.VARIABLE_NAMING_CONVENTION_VALUE);
clientCodegen.setModelPackage(LumenServerOptionsProvider.MODEL_PACKAGE_VALUE);
times = 1;
clientCodegen.setApiPackage(LumenServerOptionsProvider.API_PACKAGE_VALUE);
times = 1;
times = 1;
clientCodegen.setInvokerPackage(LumenServerOptionsProvider.INVOKER_PACKAGE_VALUE);
times = 1;
clientCodegen.setPackagePath(LumenServerOptionsProvider.PACKAGE_PATH_VALUE);
times = 1;
clientCodegen.setSrcBasePath(LumenServerOptionsProvider.SRC_BASE_PATH_VALUE);
times = 1;
clientCodegen.setGitUserId(LumenServerOptionsProvider.GIT_USER_ID_VALUE);
times = 1;
clientCodegen.setGitRepoId(LumenServerOptionsProvider.GIT_REPO_ID_VALUE);
times = 1;
clientCodegen.setArtifactVersion(LumenServerOptionsProvider.ARTIFACT_VERSION_VALUE);
times = 1;
}};
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package io.swagger.codegen.options;

import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.languages.AbstractPhpCodegen;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class LumenServerOptionsProvider implements OptionsProvider {
public static final String MODEL_PACKAGE_VALUE = "package";
public static final String API_PACKAGE_VALUE = "apiPackage";
public static final String SORT_PARAMS_VALUE = "false";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
public static final String VARIABLE_NAMING_CONVENTION_VALUE = "snake_case";
public static final String INVOKER_PACKAGE_VALUE = "lumen";
public static final String PACKAGE_PATH_VALUE = "php";
public static final String SRC_BASE_PATH_VALUE = "libPhp";
public static final String GIT_USER_ID_VALUE = "gitSwaggerPhp";
public static final String GIT_REPO_ID_VALUE = "git-swagger-php";
public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT";

@Override
public String getLanguage() {
Expand All @@ -18,8 +28,17 @@ public String getLanguage() {
@Override
public Map<String, String> createOptions() {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
return builder.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE)
.put(AbstractPhpCodegen.VARIABLE_NAMING_CONVENTION, VARIABLE_NAMING_CONVENTION_VALUE)
.put(AbstractPhpCodegen.PACKAGE_PATH, PACKAGE_PATH_VALUE)
.put(AbstractPhpCodegen.SRC_BASE_PATH, SRC_BASE_PATH_VALUE)
.put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE)
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(CodegenConstants.INVOKER_PACKAGE, INVOKER_PACKAGE_VALUE)
.put(CodegenConstants.GIT_USER_ID, GIT_USER_ID_VALUE)
.put(CodegenConstants.GIT_REPO_ID, GIT_REPO_ID_VALUE)
.put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE)
.build();
}

Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/lumen/.swagger-codegen-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# Thsi matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testEndpointParameters()

$date = $input['date'];

$dateTime = $input['dateTime'];
$date_time = $input['date_time'];

if (strlen($input['password']) > 64) {
throw new \InvalidArgumentException('invalid length for $password when calling FakeApi.testEndpointParameters, must be smaller than or equal to 64.');
Expand Down Expand Up @@ -169,11 +169,11 @@ public function testEnumQueryParameters()


//not path params validation
$enumQueryString = $input['enumQueryString'];
$enum_query_string = $input['enum_query_string'];

$enumQueryInteger = $input['enumQueryInteger'];
$enum_query_integer = $input['enum_query_integer'];

$enumQueryDouble = $input['enumQueryDouble'];
$enum_query_double = $input['enum_query_double'];


return response('How about implementing testEnumQueryParameters as a GET method ?');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public function findPetsByTags()
*
* Deletes a pet.
*
* @param Long $petId Pet id to delete (required)
* @param int $pet_id Pet id to delete (required)
*
* @return Http response
*/
public function deletePet($petId)
public function deletePet($pet_id)
{
$input = Request::all();

Expand All @@ -159,11 +159,11 @@ public function deletePet($petId)
*
* Find pet by ID.
*
* @param Long $petId ID of pet to return (required)
* @param int $pet_id ID of pet to return (required)
*
* @return Http response
*/
public function getPetById($petId)
public function getPetById($pet_id)
{
$input = Request::all();

Expand All @@ -179,11 +179,11 @@ public function getPetById($petId)
*
* Updates a pet in the store with form data.
*
* @param Long $petId ID of pet that needs to be updated (required)
* @param int $pet_id ID of pet that needs to be updated (required)
*
* @return Http response
*/
public function updatePetWithForm($petId)
public function updatePetWithForm($pet_id)
{
$input = Request::all();

Expand All @@ -199,11 +199,11 @@ public function updatePetWithForm($petId)
*
* uploads an image.
*
* @param Long $petId ID of pet to update (required)
* @param int $pet_id ID of pet to update (required)
*
* @return Http response
*/
public function uploadFile($petId)
public function uploadFile($pet_id)
{
$input = Request::all();

Expand Down
Loading