Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,30 @@ public void processOpts() {
this.setTemplateDir((String) additionalProperties.get(CodegenConstants.TEMPLATE_DIR));
}

//todo: replace hardcore string for constant on "CodegenConstans" class once publishing issue on codegen be resolved. (02-15-18)
if (additionalProperties.containsKey(/**fixme: CodegenConstants.TEMPLATE_VERSION*/ "templateVersion")) {
this.setTemplateVersion((String) additionalProperties.get(/**fixme: CodegenConstants.TEMPLATE_VERSION*/ "templateVersion"));
if (additionalProperties.containsKey(CodegenConstants.TEMPLATE_VERSION)) {
this.setTemplateVersion((String) additionalProperties.get(CodegenConstants.TEMPLATE_VERSION));
}

if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
this.setModelPackage((String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
} else if (StringUtils.isNotEmpty(modelPackage)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
}

if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
this.setApiPackage((String) additionalProperties.get(CodegenConstants.API_PACKAGE));
} else if (StringUtils.isNotEmpty(apiPackage)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
}

if (additionalProperties.containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString()));
} else if (sortParamsByRequiredFlag != null) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, sortParamsByRequiredFlag);
}

if (additionalProperties.containsKey(CodegenConstants.ENSURE_UNIQUE_PARAMS)) {
Expand All @@ -200,6 +208,14 @@ public void processOpts() {
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
}

if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
this.setHideGenerationTimestamp(Boolean.valueOf(additionalProperties
.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
} else if(hideGenerationTimestamp != null) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp);
}
}

public Map<String, Object> postProcessAllModels(Map<String, Object> processedModels) {
Expand Down Expand Up @@ -589,6 +605,10 @@ public void setApiPackage(String apiPackage) {
this.apiPackage = apiPackage;
}

public Boolean getSortParamsByRequiredFlag() {
return sortParamsByRequiredFlag;
}

public void setSortParamsByRequiredFlag(Boolean sortParamsByRequiredFlag) {
this.sortParamsByRequiredFlag = sortParamsByRequiredFlag;
}
Expand Down Expand Up @@ -3170,6 +3190,24 @@ public String getHttpUserAgent() {
return httpUserAgent;
}

/**
* Hide generation timestamp
*
* @param hideGenerationTimestamp flag to indicates if the generation timestamp should be hidden or not
*/
public void setHideGenerationTimestamp(Boolean hideGenerationTimestamp) {
this.hideGenerationTimestamp = hideGenerationTimestamp;
}

/**
* Hide generation timestamp
*
* @return if the generation timestamp should be hidden or not
*/
public Boolean getHideGenerationTimestamp() {
return hideGenerationTimestamp;
}

@SuppressWarnings("static-method")
protected CliOption buildLibraryCliOption(Map<String, String> supportedLibraries) {
StringBuilder sb = new StringBuilder("library template (sub-template) to use:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public AbstractJavaCodegen() {
cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, CodegenConstants
.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util. This option only works for Java API client"));
cliOptions.add(new CliOption("hideGenerationTimestamp", "hides the timestamp when files were generated"));
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC));
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));

CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
Expand All @@ -167,20 +167,6 @@ public AbstractJavaCodegen() {

@Override
public void processOpts() {
super.processOpts();

modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
apiTestTemplateFiles.put("api_test.mustache", ".java");
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");

if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
}
additionalProperties.put(SUPPORT_JAVA6, supportJava6);


if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
} else if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
Expand All @@ -195,95 +181,119 @@ public void processOpts() {
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derviedInvokerPackage);
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
LOGGER.info("Invoker Package Name, originally not set, is now dervied from model package name: " + derviedInvokerPackage);
} else {
//not set, use default to be passed to template
} else if (StringUtils.isNotEmpty(invokerPackage)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
}

super.processOpts();

modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
apiTestTemplateFiles.put("api_test.mustache", ".java");
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");

if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
}
additionalProperties.put(SUPPORT_JAVA6, supportJava6);

if (additionalProperties.containsKey(CodegenConstants.GROUP_ID)) {
this.setGroupId((String) additionalProperties.get(CodegenConstants.GROUP_ID));
} else {
//not set, use to be passed to template
} else if(StringUtils.isNotEmpty(groupId)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
}

if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_ID)) {
this.setArtifactId((String) additionalProperties.get(CodegenConstants.ARTIFACT_ID));
} else {
//not set, use to be passed to template
} else if(StringUtils.isNotEmpty(artifactId)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
}

if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
} else {
//not set, use to be passed to template
} else if(StringUtils.isNotEmpty(artifactVersion)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
}

if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_URL)) {
this.setArtifactUrl((String) additionalProperties.get(CodegenConstants.ARTIFACT_URL));
} else {
} else if(StringUtils.isNoneEmpty(artifactUrl)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.ARTIFACT_URL, artifactUrl);
}

if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_DESCRIPTION)) {
this.setArtifactDescription((String) additionalProperties.get(CodegenConstants.ARTIFACT_DESCRIPTION));
} else {
} else if(StringUtils.isNoneEmpty(artifactDescription)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.ARTIFACT_DESCRIPTION, artifactDescription);
}

if (additionalProperties.containsKey(CodegenConstants.SCM_CONNECTION)) {
this.setScmConnection((String) additionalProperties.get(CodegenConstants.SCM_CONNECTION));
} else {
} else if(StringUtils.isNoneEmpty(scmConnection)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.SCM_CONNECTION, scmConnection);
}

if (additionalProperties.containsKey(CodegenConstants.SCM_DEVELOPER_CONNECTION)) {
this.setScmDeveloperConnection((String) additionalProperties.get(CodegenConstants.SCM_DEVELOPER_CONNECTION));
} else {
} else if(StringUtils.isNoneEmpty(scmDeveloperConnection)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.SCM_DEVELOPER_CONNECTION, scmDeveloperConnection);
}

if (additionalProperties.containsKey(CodegenConstants.SCM_URL)) {
this.setScmUrl((String) additionalProperties.get(CodegenConstants.SCM_URL));
} else {
} else if(StringUtils.isNoneEmpty(scmUrl)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.SCM_URL, scmUrl);
}

if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_NAME)) {
this.setDeveloperName((String) additionalProperties.get(CodegenConstants.DEVELOPER_NAME));
} else {
} else if(StringUtils.isNoneEmpty(developerName)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.DEVELOPER_NAME, developerName);
}

if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_EMAIL)) {
this.setDeveloperEmail((String) additionalProperties.get(CodegenConstants.DEVELOPER_EMAIL));
} else {
} else if(StringUtils.isNoneEmpty(developerEmail)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.DEVELOPER_EMAIL, developerEmail);
}

if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_ORGANIZATION)) {
this.setDeveloperOrganization((String) additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION));
} else {
} else if(StringUtils.isNoneEmpty(developerOrganization)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION, developerOrganization);
}

if (additionalProperties.containsKey(CodegenConstants.DEVELOPER_ORGANIZATION_URL)) {
this.setDeveloperOrganizationUrl((String) additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION_URL));
} else {
} else if(StringUtils.isNoneEmpty(developerOrganizationUrl)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION_URL, developerOrganizationUrl);
}

if (additionalProperties.containsKey(CodegenConstants.LICENSE_NAME)) {
this.setLicenseName((String) additionalProperties.get(CodegenConstants.LICENSE_NAME));
} else {
} else if(StringUtils.isNoneEmpty(licenseName)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
}

if (additionalProperties.containsKey(CodegenConstants.LICENSE_URL)) {
this.setLicenseUrl((String) additionalProperties.get(CodegenConstants.LICENSE_URL));
} else {
} else if(StringUtils.isNoneEmpty(licenseUrl)) {
// not set in additionalProperties, add value from CodegenConfig in order to use it in templates
additionalProperties.put(CodegenConstants.LICENSE_URL, licenseUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue;
import static java.util.Collections.sort;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenArgument;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
Expand All @@ -18,23 +16,25 @@
import io.swagger.codegen.languages.features.GzipFeatures;
import io.swagger.codegen.languages.features.PerformBeanValidationFeatures;

import io.swagger.v3.core.util.Yaml;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

public class JavaClientCodegen extends AbstractJavaCodegen implements BeanValidationFeatures, PerformBeanValidationFeatures, GzipFeatures {
static final String MEDIA_TYPE = "mediaType";

@SuppressWarnings("hiding")
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);

public static final String USE_RX_JAVA = "useRxJava";
Expand Down
Loading