Skip to content

Commit 69f8274

Browse files
committed
Merge pull request #1272 from wing328/add_cli_parameter_order
Add CLI option to sort method arguments
2 parents 770ea9d + 4e4e9e7 commit 69f8274

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ public class CodegenConstants {
3737
public static final String LIBRARY = "library";
3838
public static final String LIBRARY_DESC = "library template (sub-template)";
3939

40+
public static final String SORT_PARAMS_BY_REQUIRED_FLAG = "sortParamsByRequiredFlag";
41+
public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC = "Sort method arguments to place required parameters before optional parameters. Default: true";
42+
4043
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public void processOpts() {
103103
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
104104
this.setApiPackage((String) additionalProperties.get(CodegenConstants.API_PACKAGE));
105105
}
106+
107+
if (additionalProperties.containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
108+
this.setSortParamsByRequiredFlag(Boolean.valueOf((String)additionalProperties.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString()));
109+
}
106110
}
107111

108112
// override with any special post-processing
@@ -227,6 +231,10 @@ public void setApiPackage(String apiPackage) {
227231
this.apiPackage = apiPackage;
228232
}
229233

234+
public void setSortParamsByRequiredFlag(Boolean sortParamsByRequiredFlag) {
235+
this.sortParamsByRequiredFlag = sortParamsByRequiredFlag;
236+
}
237+
230238
public String toApiFilename(String name) {
231239
return toApiName(name);
232240
}
@@ -344,6 +352,7 @@ public DefaultCodegen() {
344352

345353
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
346354
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
355+
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
347356
}
348357

349358

@@ -1034,8 +1043,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
10341043
}
10351044
op.bodyParam = bodyParam;
10361045
op.httpMethod = httpMethod.toUpperCase();
1037-
// move "required" parameters in front of "optional" parameters
10381046

1047+
// move "required" parameters in front of "optional" parameters
10391048
if(sortParamsByRequiredFlag) {
10401049
Collections.sort(allParams, new Comparator<CodegenParameter>() {
10411050
@Override

samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public function logoutUser()
409409
*
410410
* Get user by user name
411411
*
412-
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
412+
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
413413
* @return \Swagger\Client\Model\User
414414
* @throws \Swagger\Client\ApiException on non-2xx response
415415
*/

samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class ApiClient
4848
public static $PATCH = "PATCH";
4949
public static $POST = "POST";
5050
public static $GET = "GET";
51+
public static $HEAD = "HEAD";
52+
public static $OPTIONS = "OPTIONS";
5153
public static $PUT = "PUT";
5254
public static $DELETE = "DELETE";
5355

@@ -170,6 +172,11 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
170172
if ($method == self::$POST) {
171173
curl_setopt($curl, CURLOPT_POST, true);
172174
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
175+
} else if ($method == self::$HEAD) {
176+
curl_setopt($curl, CURLOPT_NOBODY, true);
177+
} else if ($method == self::$OPTIONS) {
178+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
179+
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
173180
} else if ($method == self::$PATCH) {
174181
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
175182
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);

0 commit comments

Comments
 (0)