forked from loafle/openapi-generator-original
added @ApiModelProperty and @JsonIgnore annotations, set defailtValue to java library option
This commit is contained in:
parent
4eeee3b24d
commit
dcd8302f42
@ -1,7 +1,10 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -22,6 +25,7 @@ public class CliOption {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@ApiModelProperty(name = "optionName")
|
||||
public String getOpt() {
|
||||
return opt;
|
||||
}
|
||||
@ -34,6 +38,7 @@ public class CliOption {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "Data type is based on the types supported by the JSON-Schema")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@ -50,6 +55,11 @@ public class CliOption {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public CliOption defaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CliOption addEnum(String value, String description) {
|
||||
if (this.enumValues == null) {
|
||||
this.enumValues = new LinkedHashMap<String, String>();
|
||||
@ -66,11 +76,14 @@ public class CliOption {
|
||||
|
||||
public void setEnum(Map<String, String> enumValues) {
|
||||
this.enumValues = enumValues;
|
||||
this.type = "enum";
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getOptionHelp() {
|
||||
StringBuilder sb = new StringBuilder(description);
|
||||
if(defaultValue != null) {
|
||||
sb.append(" (Default: ").append(defaultValue).append(")");
|
||||
}
|
||||
if (enumValues != null) {
|
||||
for (Map.Entry<String, String> entry : enumValues.entrySet()) {
|
||||
sb.append("\n ").append(entry.getKey()).append(" - ").append(entry.getValue());
|
||||
|
@ -38,7 +38,7 @@ public class CodegenConstants {
|
||||
public static final String LIBRARY_DESC = "library template (sub-template)";
|
||||
|
||||
public static final String SORT_PARAMS_BY_REQUIRED_FLAG = "sortParamsByRequiredFlag";
|
||||
public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC = "Sort method arguments to place required parameters before optional parameters. Default: true";
|
||||
public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC = "Sort method arguments to place required parameters before optional parameters.";
|
||||
|
||||
public static final String ENSURE_UNIQUE_PARAMS = "ensureUniqueParams";
|
||||
public static final String ENSURE_UNIQUE_PARAMS_DESC = "Whether to ensure parameter names are unique in an operation (rename parameters that are not). Default: true";
|
||||
|
@ -445,7 +445,8 @@ public class DefaultCodegen {
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue("true"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants.ENSURE_UNIQUE_PARAMS_DESC));
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, "artifactId for use in the generated build.gradle and pom.xml"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "artifact version for use in the generated build.gradle and pom.xml"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin. Default is true."));
|
||||
cliOptions.add(new CliOption(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin.")
|
||||
.defaultValue("true"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
|
@ -80,8 +80,9 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("object", "Object");
|
||||
|
||||
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.PACKAGE_NAME, "C# package name (convention: Camel.Case).")
|
||||
.defaultValue("IO.Swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "C# package version.").defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,11 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
typeMapping.put("object", "Object");
|
||||
|
||||
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(CLIENT_PACKAGE, "C# client package name (convention: Camel.Case), default: IO.Swagger.Client"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "C# package name (convention: Camel.Case).")
|
||||
.defaultValue("IO.Swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "C# package version.").defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CLIENT_PACKAGE, "C# client package name (convention: Camel.Case).")
|
||||
.defaultValue("IO.Swagger.Client"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,9 +75,9 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "flash package name (convention:" +
|
||||
" package.name), default: io.swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "flash package version, " +
|
||||
"default: 1.0.0"));
|
||||
" package.name)").defaultValue("io.swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "flash package version")
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "source folder for generated " +
|
||||
"code. e.g. src/main/flex"));
|
||||
|
@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
@ -90,14 +91,17 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
||||
cliOptions.add(new CliOption(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util (default to false)"));
|
||||
cliOptions.add(new CliOption(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util")
|
||||
.defaultValue("false"));
|
||||
|
||||
supportedLibraries.put("<default>", "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
|
||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
|
||||
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
|
||||
supportedLibraries.put("retrofit", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use:");
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
library.setEnum(supportedLibraries);
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
cliOptions.add(library);
|
||||
}
|
||||
|
||||
|
@ -120,13 +120,17 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
instantiationTypes.put("map", "NSMutableDictionary");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CLASS_PREFIX, "prefix for generated classes (convention: Abbreviation of pod name e.g. `HN` for `HackerNews`), default: `SWG`"));
|
||||
cliOptions.add(new CliOption(POD_NAME, "cocoapods package name (convention: CameCase), default: `SwaggerClient`"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.POD_VERSION, "cocoapods package version, default: `1.0.0`"));
|
||||
cliOptions.add(new CliOption(AUTHOR_NAME, "Name to use in the podspec file, default: `Swagger`"));
|
||||
cliOptions.add(new CliOption(AUTHOR_EMAIL, "Email to use in the podspec file, default: `apiteam@swagger.io`"));
|
||||
cliOptions.add(new CliOption(GIT_REPO_URL, "URL for the git repo where this podspec should point to, default: `https://github.com/swagger-api/swagger-codegen`"));
|
||||
cliOptions.add(new CliOption(LICENSE, "License to use in the podspec file, default: `MIT`"));
|
||||
cliOptions.add(new CliOption(CLASS_PREFIX, "prefix for generated classes (convention: Abbreviation of pod name e.g. `HN` for `HackerNews`).`")
|
||||
.defaultValue("SWG"));
|
||||
cliOptions.add(new CliOption(POD_NAME, "cocoapods package name (convention: CameCase).")
|
||||
.defaultValue("SwaggerClient"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.POD_VERSION, "cocoapods package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(AUTHOR_NAME, "Name to use in the podspec file.").defaultValue("Swagger"));
|
||||
cliOptions.add(new CliOption(AUTHOR_EMAIL, "Email to use in the podspec file.").defaultValue("apiteam@swagger.io"));
|
||||
cliOptions.add(new CliOption(GIT_REPO_URL, "URL for the git repo where this podspec should point to.")
|
||||
.defaultValue("https://github.com/swagger-api/swagger-codegen"));
|
||||
cliOptions.add(new CliOption(LICENSE, "License to use in the podspec file.").defaultValue("MIT"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
|
@ -70,8 +70,8 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("object", "object");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "perl module name (convention: CamelCase), default: SwaggerClient"));
|
||||
cliOptions.add(new CliOption(MODULE_VERSION, "perl module version, default: 1.0.0"));
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "perl module name (convention: CamelCase).").defaultValue("SwaggerClient"));
|
||||
cliOptions.add(new CliOption(MODULE_VERSION, "perl module version.").defaultValue("1.0.0"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,7 +91,8 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("DateTime", "\\DateTime");
|
||||
|
||||
cliOptions.add(new CliOption(VARIABLE_NAMING_CONVENTION, "naming convention of variable name, e.g. camelCase. Default: snake_case"));
|
||||
cliOptions.add(new CliOption(VARIABLE_NAMING_CONVENTION, "naming convention of variable name, e.g. camelCase.")
|
||||
.defaultValue("snake_case"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, "The main namespace to use for all classes. e.g. Yay\\Pets"));
|
||||
cliOptions.add(new CliOption(PACKAGE_PATH, "The main package name for classes. e.g. GeneratedPetstore"));
|
||||
cliOptions.add(new CliOption(SRC_BASE_PATH, "The directory under packagePath to serve as source root."));
|
||||
|
@ -63,9 +63,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"return", "def", "for", "lambda", "try"));
|
||||
|
||||
cliOptions.clear();
|
||||
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.PACKAGE_NAME, "python package name (convention: snake_case).")
|
||||
.defaultValue("swagger_client"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "python package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
}
|
||||
|
||||
|
@ -80,9 +80,11 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
cliOptions.add(new CliOption(GEM_NAME, "gem name (convention: underscore_case), default: swagger_client"));
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "top module name (convention: CamelCase, usually corresponding to gem name), default: SwaggerClient"));
|
||||
cliOptions.add(new CliOption(GEM_VERSION, "gem version, default: 1.0.0"));
|
||||
cliOptions.add(new CliOption(GEM_NAME, "gem name (convention: underscore_case).").
|
||||
defaultValue("swagger_client"));
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "top module name (convention: CamelCase, usually corresponding" +
|
||||
" to gem name).").defaultValue("SwaggerClient"));
|
||||
cliOptions.add(new CliOption(GEM_VERSION, "gem version.").defaultValue("1.0.0"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,7 +120,7 @@ public class SwaggerResource {
|
||||
value = "Returns options for a server framework",
|
||||
response = CliOption.class,
|
||||
responseContainer = "map",
|
||||
tags = "clients")
|
||||
tags = "servers")
|
||||
public Response getServerOptions(
|
||||
@Context HttpServletRequest request,
|
||||
@ApiParam(value = "The target language for the server framework", required = true)
|
||||
|
@ -81,7 +81,7 @@ public class OnlineGeneratorOptionsTest {
|
||||
{new StaticDocOptionsProvider()}, {new StaticHtmlOptionsProvider()},
|
||||
{new SwaggerOptionsProvider()}, {new SwaggerYamlOptionsProvider()},
|
||||
{new SwiftOptionsProvider()}, {new TizenClientOptionsProvider()},
|
||||
{new TypeScriptAngularClientOptionsProvider()}, {new TypeScriptNodeClientOptionsProvider()},
|
||||
{new TypeScriptAngularClientOptionsProvider()}, {new TypeScriptNodeClientOptionsProvider()}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package io.swagger.generator.online;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.languages.JavaClientCodegen;
|
||||
import io.swagger.codegen.options.JavaOptionsProvider;
|
||||
import io.swagger.generator.exception.ApiException;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class OnlineJavaClientOptionsTest {
|
||||
|
||||
@Test
|
||||
public void getOptionsTest() throws ApiException {
|
||||
final Map<String, CliOption> options = Generator.getOptions(new JavaOptionsProvider().getLanguage());
|
||||
assertNotNull(options);
|
||||
final CliOption opt = options.get(CodegenConstants.LIBRARY);
|
||||
assertNotNull(opt);
|
||||
assertEquals(opt.getDefault(), JavaClientCodegen.DEFAULT_LIBRARY);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user