mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
Added support for sortParamsByRequiredFlag config option to C# and Python
This commit is contained in:
parent
28069fa1b4
commit
5da0b96f17
@ -262,6 +262,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
operation.put("classVarName", config.toApiVarName(tag));
|
||||
operation.put("importPath", config.toApiImport(tag));
|
||||
|
||||
// Pass sortParamsByRequiredFlag through to the Mustache template...
|
||||
boolean sortParamsByRequiredFlag = true;
|
||||
if (this.config.additionalProperties().containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
|
||||
sortParamsByRequiredFlag = Boolean.valueOf((String)this.config.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString());
|
||||
}
|
||||
operation.put("sortParamsByRequiredFlag", sortParamsByRequiredFlag);
|
||||
|
||||
processMimeTypes(swagger.getConsumes(), operation, "consumes");
|
||||
processMimeTypes(swagger.getProduces(), operation, "produces");
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "C# package name (convention: Camel.Case), default: IO.Swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "C# package version, default: 1.0.0"));
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,6 +66,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case)," +
|
||||
" default: swagger_client"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "python package version, default: 1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +47,7 @@ class {{classname}}(object):
|
||||
self.api_client = config.api_client
|
||||
{{#operation}}
|
||||
|
||||
def {{nickname}}(self, {{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}**kwargs):
|
||||
def {{nickname}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):
|
||||
"""
|
||||
{{{summary}}}
|
||||
{{{notes}}}
|
||||
@ -58,7 +58,12 @@ class {{classname}}(object):
|
||||
>>> def callback_function(response):
|
||||
>>> pprint(response)
|
||||
>>>
|
||||
{{#sortParamsByRequiredFlag}}
|
||||
>>> thread = api.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}callback=callback_function)
|
||||
{{/sortParamsByRequiredFlag}}
|
||||
{{^sortParamsByRequiredFlag}}
|
||||
>>> thread = api.{{nickname}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
|
||||
{{/sortParamsByRequiredFlag}}
|
||||
|
||||
:param callback function: The callback function
|
||||
for asynchronous request. (optional)
|
||||
@ -69,13 +74,6 @@ class {{classname}}(object):
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
"""
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
# verify the required parameter '{{paramName}}' is set
|
||||
if {{paramName}} is None:
|
||||
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{nickname}}`")
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
|
||||
all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}]
|
||||
all_params.append('callback')
|
||||
@ -90,6 +88,14 @@ class {{classname}}(object):
|
||||
params[key] = val
|
||||
del params['kwargs']
|
||||
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
# verify the required parameter '{{paramName}}' is set
|
||||
if ('{{paramName}}' not in params) or (params['{{paramName}}'] is None):
|
||||
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{nickname}}`")
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
|
||||
resource_path = '{{path}}'.replace('{format}', 'json')
|
||||
method = '{{httpMethod}}'
|
||||
|
||||
|
@ -38,6 +38,7 @@ public class CSharpClientOptionsTest extends AbstractOptionsTest {
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||
return builder.put(CodegenConstants.PACKAGE_NAME, PACKAGE_NAME_VALUE)
|
||||
.put(CodegenConstants.PACKAGE_VERSION, PACKAGE_VERSION_VALUE)
|
||||
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "true")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class PythonClientOptionsTest extends AbstractOptionsTest {
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||
return builder.put(CodegenConstants.PACKAGE_NAME, PACKAGE_NAME_VALUE)
|
||||
.put(CodegenConstants.PACKAGE_VERSION, PACKAGE_VERSION_VALUE)
|
||||
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "true")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user