forked from loafle/openapi-generator-original
Merge pull request #3165 from abcsun/lumen
[PHP Lumen] sort the endpoints in ascending to avoid the route priority issure
This commit is contained in:
@@ -5,23 +5,16 @@ import io.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
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 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.
|
||||
@@ -95,12 +88,12 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
/**
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "io.swagger.client.api";
|
||||
apiPackage = "app.Http.Controllers";
|
||||
|
||||
/**
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "io.swagger.client.model";
|
||||
modelPackage = "models";
|
||||
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
@@ -161,7 +154,7 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,10 +163,28 @@ public class LumenServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/app/Http/controllers";
|
||||
// return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);//"/app/Http/controllers";
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
|
||||
// sort the endpoints in ascending to avoid the route priority issure.
|
||||
// https://github.com/swagger-api/swagger-codegen/issues/2643
|
||||
Collections.sort(operations, new Comparator<CodegenOperation>() {
|
||||
@Override
|
||||
public int compare(CodegenOperation lhs, CodegenOperation rhs) {
|
||||
return lhs.path.compareTo(rhs.path);
|
||||
}
|
||||
});
|
||||
|
||||
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
|
||||
|
||||
@@ -63,15 +63,14 @@ class PetApi extends Controller
|
||||
return response('How about implementing addPet as a POST method ?');
|
||||
}
|
||||
/**
|
||||
* Operation deletePet
|
||||
* Operation updatePet
|
||||
*
|
||||
* Deletes a pet.
|
||||
* Update an existing pet.
|
||||
*
|
||||
* @param Long $petId Pet id to delete (required)
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function deletePet($petId)
|
||||
public function updatePet()
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
@@ -79,8 +78,13 @@ class PetApi extends Controller
|
||||
|
||||
|
||||
//not path params validation
|
||||
if (!isset($input['body'])) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter $body when calling updatePet');
|
||||
}
|
||||
$body = $input['body'];
|
||||
|
||||
return response('How about implementing deletePet as a DELETE method ?');
|
||||
|
||||
return response('How about implementing updatePet as a PUT method ?');
|
||||
}
|
||||
/**
|
||||
* Operation findPetsByStatus
|
||||
@@ -130,6 +134,26 @@ class PetApi extends Controller
|
||||
|
||||
return response('How about implementing findPetsByTags as a GET method ?');
|
||||
}
|
||||
/**
|
||||
* Operation deletePet
|
||||
*
|
||||
* Deletes a pet.
|
||||
*
|
||||
* @param Long $petId Pet id to delete (required)
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function deletePet($petId)
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing deletePet as a DELETE method ?');
|
||||
}
|
||||
/**
|
||||
* Operation getPetById
|
||||
*
|
||||
@@ -150,30 +174,6 @@ class PetApi extends Controller
|
||||
|
||||
return response('How about implementing getPetById as a GET method ?');
|
||||
}
|
||||
/**
|
||||
* Operation updatePet
|
||||
*
|
||||
* Update an existing pet.
|
||||
*
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function updatePet()
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
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 ?');
|
||||
}
|
||||
/**
|
||||
* Operation updatePetWithForm
|
||||
*
|
||||
|
||||
@@ -38,6 +38,49 @@ class StoreApi extends Controller
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation getInventory
|
||||
*
|
||||
* Returns pet inventories by status.
|
||||
*
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function getInventory()
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing getInventory 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 ?');
|
||||
}
|
||||
/**
|
||||
* Operation deleteOrder
|
||||
*
|
||||
@@ -61,25 +104,6 @@ class StoreApi extends Controller
|
||||
|
||||
return response('How about implementing deleteOrder as a DELETE method ?');
|
||||
}
|
||||
/**
|
||||
* Operation getInventory
|
||||
*
|
||||
* Returns pet inventories by status.
|
||||
*
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function getInventory()
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing getInventory as a GET method ?');
|
||||
}
|
||||
/**
|
||||
* Operation getOrderById
|
||||
*
|
||||
@@ -106,28 +130,4 @@ class StoreApi extends Controller
|
||||
|
||||
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 ?');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,46 +110,6 @@ class UserApi extends Controller
|
||||
|
||||
return response('How about implementing createUsersWithListInput as a POST method ?');
|
||||
}
|
||||
/**
|
||||
* Operation deleteUser
|
||||
*
|
||||
* Delete user.
|
||||
*
|
||||
* @param String $username The name that needs to be deleted (required)
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function deleteUser($username)
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing deleteUser as a DELETE method ?');
|
||||
}
|
||||
/**
|
||||
* Operation getUserByName
|
||||
*
|
||||
* Get user by user name.
|
||||
*
|
||||
* @param String $username The name that needs to be fetched. Use user1 for testing. (required)
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function getUserByName($username)
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing getUserByName as a GET method ?');
|
||||
}
|
||||
/**
|
||||
* Operation loginUser
|
||||
*
|
||||
@@ -198,6 +158,46 @@ class UserApi extends Controller
|
||||
|
||||
return response('How about implementing logoutUser as a GET method ?');
|
||||
}
|
||||
/**
|
||||
* Operation deleteUser
|
||||
*
|
||||
* Delete user.
|
||||
*
|
||||
* @param String $username The name that needs to be deleted (required)
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function deleteUser($username)
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing deleteUser as a DELETE method ?');
|
||||
}
|
||||
/**
|
||||
* Operation getUserByName
|
||||
*
|
||||
* Get user by user name.
|
||||
*
|
||||
* @param String $username The name that needs to be fetched. Use user1 for testing. (required)
|
||||
*
|
||||
* @return Http response
|
||||
*/
|
||||
public function getUserByName($username)
|
||||
{
|
||||
$input = Request::all();
|
||||
|
||||
//path params validation
|
||||
|
||||
|
||||
//not path params validation
|
||||
|
||||
return response('How about implementing getUserByName as a GET method ?');
|
||||
}
|
||||
/**
|
||||
* Operation updateUser
|
||||
*
|
||||
|
||||
@@ -48,12 +48,12 @@ $app->POST('/fake', 'FakeApi@testEndpointParameters');
|
||||
*/
|
||||
$app->POST('/pet', 'PetApi@addPet');
|
||||
/**
|
||||
* DELETE deletePet
|
||||
* Summary: Deletes a pet
|
||||
* PUT updatePet
|
||||
* Summary: Update an existing pet
|
||||
* Notes:
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*/
|
||||
$app->DELETE('/pet/{petId}', 'PetApi@deletePet');
|
||||
$app->PUT('/pet', 'PetApi@updatePet');
|
||||
/**
|
||||
* GET findPetsByStatus
|
||||
* Summary: Finds Pets by status
|
||||
@@ -68,6 +68,13 @@ $app->GET('/pet/findByStatus', 'PetApi@findPetsByStatus');
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*/
|
||||
$app->GET('/pet/findByTags', 'PetApi@findPetsByTags');
|
||||
/**
|
||||
* DELETE deletePet
|
||||
* Summary: Deletes a pet
|
||||
* Notes:
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*/
|
||||
$app->DELETE('/pet/{petId}', 'PetApi@deletePet');
|
||||
/**
|
||||
* GET getPetById
|
||||
* Summary: Find pet by ID
|
||||
@@ -75,13 +82,6 @@ $app->GET('/pet/findByTags', 'PetApi@findPetsByTags');
|
||||
* 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
|
||||
@@ -96,13 +96,6 @@ $app->POST('/pet/{petId}', 'PetApi@updatePetWithForm');
|
||||
* 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
|
||||
@@ -110,13 +103,6 @@ $app->DELETE('/store/order/{orderId}', 'StoreApi@deleteOrder');
|
||||
* 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
|
||||
@@ -124,6 +110,20 @@ $app->GET('/store/order/{orderId}', 'StoreApi@getOrderById');
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*/
|
||||
$app->POST('/store/order', 'StoreApi@placeOrder');
|
||||
/**
|
||||
* 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 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 createUser
|
||||
* Summary: Create user
|
||||
@@ -145,20 +145,6 @@ $app->POST('/user/createWithArray', 'UserApi@createUsersWithArrayInput');
|
||||
* 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
|
||||
@@ -173,6 +159,20 @@ $app->GET('/user/login', 'UserApi@loginUser');
|
||||
* Output-Formats: [application/xml, application/json]
|
||||
*/
|
||||
$app->GET('/user/logout', 'UserApi@logoutUser');
|
||||
/**
|
||||
* 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');
|
||||
/**
|
||||
* PUT updateUser
|
||||
* Summary: Updated user
|
||||
|
||||
Reference in New Issue
Block a user