Merge pull request #884 from xhh/params-order

Make sure "required" parameters are placed in front of "optional" parameters
This commit is contained in:
wing328 2015-07-13 17:51:22 +08:00
commit 80303b524d
8 changed files with 31 additions and 13 deletions

View File

@ -18,22 +18,28 @@ if [ ! -d "${APP_DIR}" ]; then
fi
cd $APP_DIR
./bin/akka-scala-petstore.sh
./bin/android-java-petstore.sh
./bin/csharp-petstore.sh
./bin/dynamic-html.sh
./bin/html-petstore.sh
./bin/jaxrs-petstore-server.sh
./bin/java-petstore.sh
./bin/qt5-petstore.sh
./bin/jaxrs-petstore-server.sh
./bin/nodejs-petstore-server.sh
./bin/objc-petstore.sh
./bin/perl-petstore.sh
./bin/php-petstore.sh
./bin/python-petstore.sh
./bin/python3-petstore.sh
./bin/qt5-petstore.sh
./bin/retrofit-petstore.sh
./bin/ruby-petstore.sh
./bin/objc-petstore.sh
./bin/scala-async-petstore.sh
./bin/scala-petstore.sh
./bin/scalatra-petstore-server.sh
./bin/silex-petstore-server.sh
./bin/spring-mvc-petstore-server.sh
./bin/swift-petstore.sh
./bin/tizen-petstore.sh
./bin/typescript-angular-petstore.sh
./bin/typescript-node-petstore.sh

View File

@ -50,6 +50,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -851,6 +852,17 @@ public class DefaultCodegen {
}
op.bodyParam = bodyParam;
op.httpMethod = httpMethod.toUpperCase();
// move "required" parameters in front of "optional" parameters
Collections.sort(allParams, new Comparator<CodegenParameter>() {
@Override
public int compare(CodegenParameter one, CodegenParameter another) {
boolean oneRequired = one.required == null ? false : one.required;
boolean anotherRequired = another.required == null ? false : another.required;
if (oneRequired == anotherRequired) return 0;
else if (oneRequired) return -1;
else return 1;
}
});
op.allParams = addHasMore(allParams);
op.bodyParams = addHasMore(bodyParams);
op.pathParams = addHasMore(pathParams);

View File

@ -108,10 +108,10 @@ object PetApi {
* Expected answers:
* code 400 : (Invalid pet value)
*
* @param apiKey
* @param petId Pet id to delete
* @param apiKey
*/
def deletePet(apiKey: Option[String] = None, petId: Long): ApiRequest[Unit] =
def deletePet(petId: Long, apiKey: Option[String] = None): ApiRequest[Unit] =
ApiRequest[Unit](ApiMethods.DELETE, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/json")
.withPathParam("petId", petId)
.withHeaderParam("api_key", apiKey)

View File

@ -392,11 +392,11 @@ public class PetApi {
/**
* Deletes a pet
*
* @param apiKey
* @param petId Pet id to delete
* @param apiKey
* @return void
*/
public void deletePet (String apiKey, Long petId) throws ApiException {
public void deletePet (Long petId, String apiKey) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set

View File

@ -118,7 +118,7 @@ public class PetApiTest {
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.deletePet(null, fetched.getId());
api.deletePet(fetched.getId(), null);
try {
fetched = api.getPetById(fetched.getId());

View File

@ -418,11 +418,11 @@ public class PetApi {
/**
* Deletes a pet
*
* @param apiKey
* @param petId Pet id to delete
* @param apiKey
* @return void
*/
public void deletePet (String apiKey, Long petId) throws ApiException {
public void deletePet (Long petId, String apiKey) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set

View File

@ -151,7 +151,7 @@ public class PetApiTest {
api.addPet(pet);
Pet fetched = api.getPetById(pet.getId());
api.deletePet(null, fetched.getId());
api.deletePet(fetched.getId(), null);
try {
fetched = api.getPetById(fetched.getId());

View File

@ -537,12 +537,12 @@ class PetApi
*
* Deletes a pet
*
* @param string $api_key (optional)
* @param int $pet_id Pet id to delete (required)
* @param string $api_key (optional)
* @return void
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function deletePet($api_key=null, $pet_id)
public function deletePet($pet_id, $api_key=null)
{
// verify the required parameter 'pet_id' is set