mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
* Java generators: use codegen fields in mustable * Java generators: use codegen fields in mustable * Java generators: use codegen fields in mustable * Use MUSTACHE_PARENT_CONTEXT in additionalProperties * Fix link to mustache documentation
This commit is contained in:
parent
989a79811a
commit
129e4dc9c9
@ -232,6 +232,8 @@ public class CodegenConstants {
|
||||
public static final String TEMPLATING_ENGINE = "templatingEngine";
|
||||
public static final String TEMPLATING_ENGINE_DESC = "The templating engine plugin to use: \"mustache\" (default) or \"handlebars\" (beta)";
|
||||
|
||||
public static final String MUSTACHE_PARENT_CONTEXT = "MUSTACHE_PARENT_CONTEXT";
|
||||
|
||||
public static enum PARAM_NAMING_TYPE {camelCase, PascalCase, snake_case, original}
|
||||
|
||||
public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, original}
|
||||
|
@ -76,6 +76,7 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@ -336,125 +337,57 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return cliOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* add this instance to additionalProperties.
|
||||
* This instance is used as parent context in Mustache.
|
||||
* It means that Mustache uses the values found in this order:
|
||||
* first from additionalProperties
|
||||
* then from the getter in this instance
|
||||
* then from the fields in this instance
|
||||
*
|
||||
*/
|
||||
protected void useCodegenAsMustacheParentContext() {
|
||||
additionalProperties.put(CodegenConstants.MUSTACHE_PARENT_CONTEXT, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.TEMPLATE_DIR)) {
|
||||
this.setTemplateDir((String) additionalProperties.get(CodegenConstants.TEMPLATE_DIR));
|
||||
if (!additionalProperties.containsKey(CodegenConstants.MUSTACHE_PARENT_CONTEXT)) {
|
||||
// by default empty parent context
|
||||
additionalProperties.put(CodegenConstants.MUSTACHE_PARENT_CONTEXT, new Object());
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.TEMPLATE_DIR, this::setTemplateDir);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.MODEL_PACKAGE, this::setModelPackage);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.API_PACKAGE, this::setApiPackage);
|
||||
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.HIDE_GENERATION_TIMESTAMP, this::setHideGenerationTimestamp);
|
||||
// put the value back in additionalProperties for backward compatibility with generators not using yet convertPropertyToBooleanAndWriteBack
|
||||
writePropertyBack(CodegenConstants.HIDE_GENERATION_TIMESTAMP, isHideGenerationTimestamp());
|
||||
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, this::setSortParamsByRequiredFlag);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, this::setSortModelPropertiesByRequiredFlag);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, this::setPrependFormOrBodyParameters);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.ENSURE_UNIQUE_PARAMS, this::setEnsureUniqueParams);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, this::setAllowUnicodeIdentifiers);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.API_NAME_PREFIX, this::setApiNamePrefix);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.API_NAME_SUFFIX, this::setApiNameSuffix);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.MODEL_NAME_PREFIX, this::setModelNamePrefix);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.MODEL_NAME_SUFFIX, this::setModelNameSuffix);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.REMOVE_OPERATION_ID_PREFIX, this::setRemoveOperationIdPrefix);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DELIMITER, this::setRemoveOperationIdPrefixDelimiter);
|
||||
convertPropertyToTypeAndWriteBack(CodegenConstants.REMOVE_OPERATION_ID_PREFIX_COUNT, Integer::parseInt, this::setRemoveOperationIdPrefixCount);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.SKIP_OPERATION_EXAMPLE, this::setSkipOperationExample);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.DOCEXTENSION, this::setDocExtension);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.ENABLE_POST_PROCESS_FILE, this::setEnablePostProcessFile);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.GENERATE_ALIAS_AS_MODEL, ModelUtils::setGenerateAliasAsModel);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.REMOVE_ENUM_VALUE_PREFIX, this::setRemoveEnumValuePrefix);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR, this::setLegacyDiscriminatorBehavior);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT, this::setDisallowAdditionalPropertiesIfNotPresent);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE, this::setEnumUnknownDefaultCase);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.AUTOSET_CONSTANTS, this::setAutosetConstants);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
|
||||
this.setModelPackage((String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||
this.setApiPackage((String) additionalProperties.get(CodegenConstants.API_PACKAGE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
|
||||
setHideGenerationTimestamp(convertPropertyToBooleanAndWriteBack(CodegenConstants.HIDE_GENERATION_TIMESTAMP));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
|
||||
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG)) {
|
||||
this.setSortModelPropertiesByRequiredFlag(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS)) {
|
||||
this.setPrependFormOrBodyParameters(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ENSURE_UNIQUE_PARAMS)) {
|
||||
this.setEnsureUniqueParams(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.ENSURE_UNIQUE_PARAMS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS)) {
|
||||
this.setAllowUnicodeIdentifiers(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.API_NAME_PREFIX)) {
|
||||
this.setApiNamePrefix((String) additionalProperties.get(CodegenConstants.API_NAME_PREFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.API_NAME_SUFFIX)) {
|
||||
this.setApiNameSuffix((String) additionalProperties.get(CodegenConstants.API_NAME_SUFFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_NAME_PREFIX)) {
|
||||
this.setModelNamePrefix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_PREFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_NAME_SUFFIX)) {
|
||||
this.setModelNameSuffix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
|
||||
this.setRemoveOperationIdPrefix(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DELIMITER)) {
|
||||
this.setRemoveOperationIdPrefixDelimiter(additionalProperties
|
||||
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DELIMITER).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX_COUNT)) {
|
||||
this.setRemoveOperationIdPrefixCount(Integer.parseInt(additionalProperties
|
||||
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX_COUNT).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SKIP_OPERATION_EXAMPLE)) {
|
||||
this.setSkipOperationExample(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.SKIP_OPERATION_EXAMPLE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.DOCEXTENSION)) {
|
||||
this.setDocExtension(String.valueOf(additionalProperties
|
||||
.get(CodegenConstants.DOCEXTENSION).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ENABLE_POST_PROCESS_FILE)) {
|
||||
this.setEnablePostProcessFile(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.ENABLE_POST_PROCESS_FILE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.GENERATE_ALIAS_AS_MODEL)) {
|
||||
ModelUtils.setGenerateAliasAsModel(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.GENERATE_ALIAS_AS_MODEL).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.REMOVE_ENUM_VALUE_PREFIX)) {
|
||||
this.setRemoveEnumValuePrefix(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.REMOVE_ENUM_VALUE_PREFIX).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR)) {
|
||||
this.setLegacyDiscriminatorBehavior(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR).toString()));
|
||||
}
|
||||
if (additionalProperties.containsKey(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT)) {
|
||||
this.setDisallowAdditionalPropertiesIfNotPresent(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT).toString()));
|
||||
}
|
||||
if (additionalProperties.containsKey(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE)) {
|
||||
this.setEnumUnknownDefaultCase(Boolean.parseBoolean(additionalProperties
|
||||
.get(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE).toString()));
|
||||
}
|
||||
if (additionalProperties.containsKey(CodegenConstants.AUTOSET_CONSTANTS)) {
|
||||
this.setAutosetConstants(
|
||||
Boolean.parseBoolean(additionalProperties.get(CodegenConstants.AUTOSET_CONSTANTS).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Preset map builder with commonly used Mustache lambdas.
|
||||
@ -6794,6 +6727,59 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* reads propertyKey from additionalProperties, converts it to a boolean and
|
||||
* writes it back to additionalProperties to be usable as a boolean in
|
||||
* mustache files.
|
||||
*
|
||||
* @param propertyKey property key
|
||||
* @param booleanSetter the setter function reference
|
||||
* @return property value as boolean or false if it does not exist
|
||||
*/
|
||||
public boolean convertPropertyToBooleanAndWriteBack(String propertyKey, Consumer<Boolean> booleanSetter) {
|
||||
if (additionalProperties.containsKey(propertyKey)) {
|
||||
boolean result = convertPropertyToBoolean(propertyKey);
|
||||
writePropertyBack(propertyKey, result);
|
||||
booleanSetter.accept(result);
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads propertyKey from additionalProperties, converts it to a boolean and
|
||||
* writes it back to additionalProperties to be usable as a boolean in
|
||||
* mustache files.
|
||||
*
|
||||
* @param propertyKey property key
|
||||
* @param stringSetter the setter function reference
|
||||
* @return property value as String or default if not found
|
||||
*/
|
||||
public String convertPropertyToStringAndWriteBack(String propertyKey, Consumer<String> stringSetter) {
|
||||
return convertPropertyToTypeAndWriteBack(propertyKey, Function.identity(), stringSetter);
|
||||
}
|
||||
|
||||
/**
|
||||
* reads propertyKey from additionalProperties, converts it to a boolean and
|
||||
* writes it back to additionalProperties to be usable as a boolean in
|
||||
* mustache files.
|
||||
*
|
||||
* @param propertyKey property key
|
||||
* @param stringSetter the setter function reference
|
||||
* @return property value as String or null if not found
|
||||
*/
|
||||
public <T> T convertPropertyToTypeAndWriteBack(String propertyKey, Function<String, T> converter, Consumer<T> stringSetter) {
|
||||
if (additionalProperties.containsKey(propertyKey)) {
|
||||
String value = additionalProperties.get(propertyKey).toString();
|
||||
T result = converter.apply(value);
|
||||
writePropertyBack(propertyKey, result);
|
||||
stringSetter.accept(result);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an override location, if any is specified, for the .openapi-generator-ignore.
|
||||
* <p>
|
||||
|
@ -179,7 +179,15 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
@Getter @Setter
|
||||
protected boolean generateConstructorWithAllArgs = false;
|
||||
@Getter @Setter
|
||||
protected boolean generateBuilder = false;
|
||||
protected boolean jackson = false;
|
||||
@Getter @Setter
|
||||
protected boolean generateBuilders;
|
||||
/**
|
||||
* useBeanValidation has been moved from child generators to AbstractJavaCodegen.
|
||||
* The reason is that getBeanValidation needs it
|
||||
*/
|
||||
@Getter @Setter
|
||||
protected boolean useBeanValidation = false;
|
||||
private Map<String, String> schemaKeyToModelNameCache = new HashMap<>();
|
||||
|
||||
public AbstractJavaCodegen() {
|
||||
@ -352,6 +360,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
useCodegenAsMustacheParentContext();
|
||||
super.processOpts();
|
||||
|
||||
if (null != defaultDocumentationProvider()) {
|
||||
@ -394,64 +403,38 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
additionalProperties.put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS)) {
|
||||
this.setGenerateConstructorWithAllArgs(convertPropertyToBoolean(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS));
|
||||
}
|
||||
writePropertyBack(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, generateConstructorWithAllArgs);
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_BUILDERS)) {
|
||||
this.setGenerateBuilder(convertPropertyToBoolean(GENERATE_BUILDERS));
|
||||
}
|
||||
writePropertyBack(GENERATE_BUILDERS, generateBuilder);
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, this::setGenerateConstructorWithAllArgs);
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_BUILDERS, this::setGenerateBuilders);
|
||||
if (StringUtils.isEmpty(System.getenv("JAVA_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try 'export JAVA_POST_PROCESS_FILE=\"/usr/local/bin/clang-format -i\"' (Linux/Mac)");
|
||||
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(DISABLE_HTML_ESCAPING)) {
|
||||
this.setDisableHtmlEscaping(Boolean.parseBoolean(additionalProperties.get(DISABLE_HTML_ESCAPING).toString()));
|
||||
}
|
||||
additionalProperties.put(DISABLE_HTML_ESCAPING, disableHtmlEscaping);
|
||||
|
||||
if (additionalProperties.containsKey(BOOLEAN_GETTER_PREFIX)) {
|
||||
this.setBooleanGetterPrefix(additionalProperties.get(BOOLEAN_GETTER_PREFIX).toString());
|
||||
}
|
||||
additionalProperties.put(BOOLEAN_GETTER_PREFIX, booleanGetterPrefix);
|
||||
|
||||
if (additionalProperties.containsKey(IGNORE_ANYOF_IN_ENUM)) {
|
||||
this.setIgnoreAnyOfInEnum(Boolean.parseBoolean(additionalProperties.get(IGNORE_ANYOF_IN_ENUM).toString()));
|
||||
}
|
||||
additionalProperties.put(IGNORE_ANYOF_IN_ENUM, ignoreAnyOfInEnum);
|
||||
|
||||
if (additionalProperties.containsKey(ADDITIONAL_MODEL_TYPE_ANNOTATIONS)) {
|
||||
String additionalAnnotationsList = additionalProperties.get(ADDITIONAL_MODEL_TYPE_ANNOTATIONS).toString();
|
||||
this.setAdditionalModelTypeAnnotations(Arrays.asList(additionalAnnotationsList.trim().split("\\s*(;|\\r?\\n)\\s*")));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS)) {
|
||||
String additionalAnnotationsList = additionalProperties.get(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS).toString();
|
||||
this.setAdditionalOneOfTypeAnnotations(Arrays.asList(additionalAnnotationsList.trim().split("\\s*(;|\\r?\\n)\\s*")));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ADDITIONAL_ENUM_TYPE_ANNOTATIONS)) {
|
||||
String additionalAnnotationsList = additionalProperties.get(ADDITIONAL_ENUM_TYPE_ANNOTATIONS).toString();
|
||||
|
||||
this.setAdditionalEnumTypeAnnotations(Arrays.asList(additionalAnnotationsList.split(";")));
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(BeanValidationFeatures.USE_BEANVALIDATION, this::setUseBeanValidation);
|
||||
convertPropertyToBooleanAndWriteBack(DISABLE_HTML_ESCAPING, this::setDisableHtmlEscaping);
|
||||
convertPropertyToStringAndWriteBack(BOOLEAN_GETTER_PREFIX, this::setBooleanGetterPrefix);
|
||||
convertPropertyToBooleanAndWriteBack(IGNORE_ANYOF_IN_ENUM, this::setIgnoreAnyOfInEnum);
|
||||
convertPropertyToTypeAndWriteBack(ADDITIONAL_MODEL_TYPE_ANNOTATIONS,
|
||||
annotations-> Arrays.asList(annotations.trim().split("\\s*(;|\\r?\\n)\\s*")),
|
||||
this::setAdditionalModelTypeAnnotations);
|
||||
convertPropertyToTypeAndWriteBack(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS,
|
||||
annotations-> Arrays.asList(annotations.trim().split("\\s*(;|\\r?\\n)\\s*")),
|
||||
this::setAdditionalOneOfTypeAnnotations);
|
||||
convertPropertyToTypeAndWriteBack(ADDITIONAL_ENUM_TYPE_ANNOTATIONS,
|
||||
annotations -> Arrays.asList(annotations.split(";")),
|
||||
this::setAdditionalEnumTypeAnnotations);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
} else if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||
// guess from api package
|
||||
String derivedInvokerPackage = deriveInvokerPackageName((String) additionalProperties.get(CodegenConstants.API_PACKAGE));
|
||||
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derivedInvokerPackage);
|
||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
this.setInvokerPackage(derivedInvokerPackage);
|
||||
LOGGER.info("Invoker Package Name, originally not set, is now derived from api package name: {}", derivedInvokerPackage);
|
||||
} else if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
|
||||
// guess from model package
|
||||
String derivedInvokerPackage = deriveInvokerPackageName((String) additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
|
||||
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derivedInvokerPackage);
|
||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
this.setInvokerPackage(derivedInvokerPackage);
|
||||
LOGGER.info("Invoker Package Name, originally not set, is now derived from model package name: {}",
|
||||
derivedInvokerPackage);
|
||||
} else {
|
||||
@ -535,85 +518,41 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
additionalProperties.put(CodegenConstants.DEVELOPER_ORGANIZATION_URL, developerOrganizationUrl);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.LICENSE_NAME)) {
|
||||
this.setLicenseName((String) additionalProperties.get(CodegenConstants.LICENSE_NAME));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.LICENSE_URL)) {
|
||||
this.setLicenseUrl((String) additionalProperties.get(CodegenConstants.LICENSE_URL));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.LICENSE_URL, licenseUrl);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||
}
|
||||
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SERIALIZABLE_MODEL)) {
|
||||
this.setSerializableModel(Boolean.valueOf(additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.LIBRARY)) {
|
||||
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING)) {
|
||||
this.setSerializeBigDecimalAsString(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING).toString()));
|
||||
}
|
||||
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.MODEL_PACKAGE, this::setModelPackage);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.API_PACKAGE, this::setApiPackage);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.GROUP_ID, this::setGroupId);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.ARTIFACT_ID, this::setArtifactId);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.ARTIFACT_URL, this::setArtifactUrl);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.ARTIFACT_DESCRIPTION, this::setArtifactDescription);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SCM_CONNECTION, this::setScmConnection);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SCM_DEVELOPER_CONNECTION, this::setScmDeveloperConnection);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SCM_URL, this::setScmUrl);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.DEVELOPER_NAME, this::setDeveloperName);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.DEVELOPER_EMAIL, this::setDeveloperEmail);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.DEVELOPER_ORGANIZATION, this::setDeveloperOrganization);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.DEVELOPER_ORGANIZATION_URL, this::setDeveloperOrganizationUrl);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.LICENSE_NAME, this::setLicenseName);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.LICENSE_URL, this::setLicenseUrl);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SOURCE_FOLDER, this::setSourceFolder);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.SERIALIZABLE_MODEL, this::setSerializableModel);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.LIBRARY, this::setLibrary);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, this::setSerializeBigDecimalAsString );
|
||||
// need to put back serializableModel (boolean) into additionalProperties as value in additionalProperties is string
|
||||
additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
|
||||
// additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
|
||||
|
||||
if (additionalProperties.containsKey(DISCRIMINATOR_CASE_SENSITIVE)) {
|
||||
this.setDiscriminatorCaseSensitive(Boolean.parseBoolean(additionalProperties.get(DISCRIMINATOR_CASE_SENSITIVE).toString()));
|
||||
} else {
|
||||
// By default, the discriminator lookup should be case sensitive. There is nothing in the OpenAPI specification
|
||||
// that indicates the lookup should be case insensitive. However, some implementations perform
|
||||
// a case-insensitive lookup.
|
||||
this.setDiscriminatorCaseSensitive(Boolean.TRUE);
|
||||
}
|
||||
additionalProperties.put(DISCRIMINATOR_CASE_SENSITIVE, this.discriminatorCaseSensitive);
|
||||
|
||||
if (additionalProperties.containsKey(WITH_XML)) {
|
||||
this.setWithXml(Boolean.parseBoolean(additionalProperties.get(WITH_XML).toString()));
|
||||
}
|
||||
additionalProperties.put(WITH_XML, withXml);
|
||||
|
||||
if (additionalProperties.containsKey(OPENAPI_NULLABLE)) {
|
||||
this.setOpenApiNullable(Boolean.parseBoolean(additionalProperties.get(OPENAPI_NULLABLE).toString()));
|
||||
}
|
||||
additionalProperties.put(OPENAPI_NULLABLE, openApiNullable);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PARENT_GROUP_ID)) {
|
||||
this.setParentGroupId((String) additionalProperties.get(CodegenConstants.PARENT_GROUP_ID));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PARENT_ARTIFACT_ID)) {
|
||||
this.setParentArtifactId((String) additionalProperties.get(CodegenConstants.PARENT_ARTIFACT_ID));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PARENT_VERSION)) {
|
||||
this.setParentVersion((String) additionalProperties.get(CodegenConstants.PARENT_VERSION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(IMPLICIT_HEADERS)) {
|
||||
this.setImplicitHeaders(Boolean.parseBoolean(additionalProperties.get(IMPLICIT_HEADERS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(IMPLICIT_HEADERS_REGEX)) {
|
||||
this.setImplicitHeadersRegex(additionalProperties.get(IMPLICIT_HEADERS_REGEX).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CAMEL_CASE_DOLLAR_SIGN)) {
|
||||
this.setCamelCaseDollarSign(Boolean.parseBoolean(additionalProperties.get(CAMEL_CASE_DOLLAR_SIGN).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_ONE_OF_INTERFACES)) {
|
||||
this.setUseOneOfInterfaces(Boolean.parseBoolean(additionalProperties.get(USE_ONE_OF_INTERFACES).toString()));
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(DISCRIMINATOR_CASE_SENSITIVE, this::setDiscriminatorCaseSensitive);
|
||||
convertPropertyToBooleanAndWriteBack(WITH_XML, this::setWithXml);
|
||||
convertPropertyToBooleanAndWriteBack(OPENAPI_NULLABLE, this::setOpenApiNullable);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.PARENT_GROUP_ID, this::setParentGroupId);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.PARENT_ARTIFACT_ID, this::setParentArtifactId);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.PARENT_VERSION, this::setParentVersion);
|
||||
convertPropertyToBooleanAndWriteBack(IMPLICIT_HEADERS, this::setImplicitHeaders);
|
||||
convertPropertyToStringAndWriteBack(IMPLICIT_HEADERS_REGEX, this::setImplicitHeadersRegex);
|
||||
convertPropertyToBooleanAndWriteBack(CAMEL_CASE_DOLLAR_SIGN, this::setCamelCaseDollarSign);
|
||||
convertPropertyToBooleanAndWriteBack(USE_ONE_OF_INTERFACES, this::setUseOneOfInterfaces);
|
||||
|
||||
if (!StringUtils.isEmpty(parentGroupId) && !StringUtils.isEmpty(parentArtifactId) && !StringUtils.isEmpty(parentVersion)) {
|
||||
additionalProperties.put("parentOverridden", true);
|
||||
@ -663,16 +602,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
// used later in recursive import in postProcessingModels
|
||||
importMapping.put("com.fasterxml.jackson.annotation.JsonProperty", "com.fasterxml.jackson.annotation.JsonCreator");
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
|
||||
setSupportAsync(Boolean.parseBoolean(additionalProperties.get(SUPPORT_ASYNC).toString()));
|
||||
if (supportAsync) {
|
||||
additionalProperties.put(SUPPORT_ASYNC, "true");
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(DATE_LIBRARY)) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(SUPPORT_ASYNC, this::setSupportAsync);
|
||||
convertPropertyToStringAndWriteBack(DATE_LIBRARY, this::setDateLibrary);
|
||||
|
||||
if ("joda".equals(dateLibrary)) {
|
||||
additionalProperties.put("joda", "true");
|
||||
@ -697,25 +628,15 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
additionalProperties.put("legacyDates", "true");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(TEST_OUTPUT)) {
|
||||
setOutputTestFolder(additionalProperties.get(TEST_OUTPUT).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_JAKARTA_EE)) {
|
||||
this.setUseJakartaEe(Boolean.parseBoolean(additionalProperties.get(USE_JAKARTA_EE).toString()));
|
||||
}
|
||||
additionalProperties.put(USE_JAKARTA_EE, useJakartaEe);
|
||||
|
||||
convertPropertyToStringAndWriteBack(TEST_OUTPUT, this::setOutputTestFolder);
|
||||
convertPropertyToBooleanAndWriteBack(USE_JAKARTA_EE, this::setUseJakartaEe);
|
||||
if (useJakartaEe) {
|
||||
applyJakartaPackage();
|
||||
} else {
|
||||
applyJavaxPackage();
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CONTAINER_DEFAULT_TO_NULL)) {
|
||||
this.setContainerDefaultToNull(Boolean.parseBoolean(additionalProperties.get(CONTAINER_DEFAULT_TO_NULL).toString()));
|
||||
}
|
||||
additionalProperties.put(CONTAINER_DEFAULT_TO_NULL, containerDefaultToNull);
|
||||
convertPropertyToBooleanAndWriteBack(CONTAINER_DEFAULT_TO_NULL, this::setContainerDefaultToNull);
|
||||
|
||||
additionalProperties.put("sanitizeGeneric", (Mustache.Lambda) (fragment, writer) -> {
|
||||
String content = fragment.execute();
|
||||
@ -859,19 +780,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
// the whole additionalProperties object is injected into the main object passed to the mustache layer
|
||||
|
||||
this.setApiPackage(sanitizePackageName(apiPackage));
|
||||
if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||
this.additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
}
|
||||
|
||||
additionalProperties.remove(CodegenConstants.API_PACKAGE);
|
||||
this.setModelPackage(sanitizePackageName(modelPackage));
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
|
||||
this.additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
}
|
||||
|
||||
additionalProperties.remove(CodegenConstants.MODEL_PACKAGE);
|
||||
this.setInvokerPackage(sanitizePackageName(invokerPackage));
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
}
|
||||
additionalProperties.remove(CodegenConstants.INVOKER_PACKAGE);
|
||||
}
|
||||
|
||||
protected void applyJavaxPackage() {
|
||||
@ -1118,7 +1031,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
* @return BeanValidation for declared type in container(array, set)
|
||||
*/
|
||||
private String getBeanValidation(Schema<?> items) {
|
||||
if (Boolean.FALSE.equals(additionalProperties.getOrDefault(BeanValidationFeatures.USE_BEANVALIDATION, Boolean.FALSE))) {
|
||||
if (!isUseBeanValidation()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -1742,12 +1655,12 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
codegenModel.imports.add("ApiModel");
|
||||
}
|
||||
}
|
||||
if (codegenModel.discriminator != null && additionalProperties.containsKey(JACKSON)) {
|
||||
if (codegenModel.discriminator != null && jackson) {
|
||||
codegenModel.imports.add("JsonSubTypes");
|
||||
codegenModel.imports.add("JsonTypeInfo");
|
||||
codegenModel.imports.add("JsonIgnoreProperties");
|
||||
}
|
||||
if (codegenModel.getIsClassnameSanitized() && additionalProperties.containsKey(JACKSON) && !codegenModel.isEnum) {
|
||||
if (codegenModel.getIsClassnameSanitized() && jackson && !codegenModel.isEnum) {
|
||||
codegenModel.imports.add("JsonTypeName");
|
||||
}
|
||||
if (allDefinitions != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
||||
@ -1789,7 +1702,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
if (serializeBigDecimalAsString && additionalProperties.containsKey(JACKSON)) {
|
||||
if (serializeBigDecimalAsString && jackson) {
|
||||
if ("decimal".equals(property.baseType) || "bigdecimal".equalsIgnoreCase(property.baseType)) {
|
||||
// we serialize BigDecimal as `string` to avoid precision loss
|
||||
property.vendorExtensions.put("x-extra-annotation", "@JsonSerialize(using = ToStringSerializer.class)");
|
||||
@ -1814,7 +1727,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
model.imports.add("Arrays");
|
||||
} else if ("set".equals(property.containerType)) {
|
||||
model.imports.add("LinkedHashSet");
|
||||
if ((!openApiNullable || !property.isNullable) && additionalProperties.containsKey(JACKSON)) { // cannot be wrapped to nullable
|
||||
if ((!openApiNullable || !property.isNullable) && jackson) { // cannot be wrapped to nullable
|
||||
model.imports.add("JsonDeserialize");
|
||||
property.vendorExtensions.put("x-setter-extra-annotation", "@JsonDeserialize(as = LinkedHashSet.class)");
|
||||
}
|
||||
@ -2387,7 +2300,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
if (jackson) {
|
||||
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo")) {
|
||||
Map<String, String> oneImport = new HashMap<>();
|
||||
oneImport.put("import", importMapping.get(i));
|
||||
|
@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
@ -60,12 +61,12 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
ARRAY_OF_MICROPROFILE_OPEN_API_SCHEMA_TYPES = Collections.unmodifiableMap(schemaTypes);
|
||||
}
|
||||
|
||||
@Setter
|
||||
protected String implFolder = "src/main/java";
|
||||
protected String testResourcesFolder = "src/test/resources";
|
||||
protected String title = "OpenAPI Server";
|
||||
protected String serverPort = "8080";
|
||||
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean useTags = false;
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(AbstractJavaJAXRSServerCodegen.class);
|
||||
@ -79,6 +80,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
dateLibrary = "legacy"; //TODO: add joda support to all jax-rs
|
||||
apiPackage = "org.openapitools.api";
|
||||
modelPackage = "org.openapitools.model";
|
||||
useBeanValidation = true;
|
||||
|
||||
// clioOptions default redefinition need to be updated
|
||||
updateOption(CodegenConstants.INVOKER_PACKAGE, this.getInvokerPackage());
|
||||
@ -90,7 +92,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
// java inflector uses the jackson lib
|
||||
additionalProperties.put(JACKSON, "true");
|
||||
this.jackson = true;
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC).defaultValue(implFolder));
|
||||
cliOptions.add(new CliOption("title", "a title describing the application").defaultValue(title));
|
||||
@ -113,19 +115,9 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_TAGS)) {
|
||||
setUseTags(convertPropertyToBoolean(USE_TAGS));
|
||||
}
|
||||
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.IMPL_FOLDER, this::setImplFolder);
|
||||
convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION, this::setUseBeanValidation);
|
||||
convertPropertyToBooleanAndWriteBack(USE_TAGS, this::setUseTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,16 +47,12 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
|
||||
|
||||
public static final String USE_ABSTRACTION_FOR_FILES = "useAbstractionForFiles";
|
||||
|
||||
@Getter protected boolean useBeanValidation = false;
|
||||
|
||||
@Getter protected boolean useGenericResponse = false;
|
||||
|
||||
@Getter protected boolean useGzipFeatureForTests = false;
|
||||
|
||||
@Getter protected boolean useLoggingFeatureForTests = false;
|
||||
|
||||
@Getter private boolean useJackson = false;
|
||||
|
||||
@Setter protected boolean useAbstractionForFiles = false;
|
||||
|
||||
public JavaCXFClientCodegen() {
|
||||
@ -102,30 +98,11 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) {
|
||||
this.setUseGenericResponse(convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_GZIP_FEATURE_FOR_TESTS)) {
|
||||
this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_LOGGING_FEATURE_FOR_TESTS)) {
|
||||
this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
useJackson = convertPropertyToBooleanAndWriteBack(JACKSON);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_ABSTRACTION_FOR_FILES)) {
|
||||
this.setUseAbstractionForFiles(convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES));
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE, this::setUseGenericResponse);
|
||||
convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS, this::setUseGzipFeatureForTests);
|
||||
convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS, this::setUseLoggingFeatureForTests);
|
||||
convertPropertyToBooleanAndWriteBack(JACKSON, this::setJackson);
|
||||
convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES, this::setUseAbstractionForFiles);
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
@ -159,7 +136,7 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
|
||||
model.imports.remove("ToStringSerializer");
|
||||
|
||||
|
||||
if (useJackson) {
|
||||
if (jackson) {
|
||||
//Add jackson imports when model has inner enum
|
||||
if (Boolean.FALSE.equals(model.isEnum) && Boolean.TRUE.equals(model.hasEnums)) {
|
||||
model.imports.add("JsonCreator");
|
||||
@ -190,10 +167,6 @@ public class JavaCXFClientCodegen extends AbstractJavaCodegen
|
||||
return "Generates a Java JAXRS Client based on Apache CXF framework.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests) {
|
||||
|
@ -1311,13 +1311,10 @@ public class JavaCXFExtServerCodegen extends JavaCXFServerCodegen implements CXF
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_SPRING_APPLICATION)) {
|
||||
this.setSupportMultipleSpringServices(
|
||||
convertPropertyToBooleanAndWriteBack(SUPPORT_MULTIPLE_SPRING_SERVICES));
|
||||
}
|
||||
if (additionalProperties.containsKey(GENERATE_OPERATION_BODY)) {
|
||||
boolean generateOperationBody = convertPropertyToBooleanAndWriteBack(GENERATE_OPERATION_BODY);
|
||||
this.setGenerateOperationBody(generateOperationBody);
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_APPLICATION, this::setSupportMultipleSpringServices);
|
||||
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_OPERATION_BODY, this::setGenerateOperationBody);
|
||||
if (generateOperationBody) {
|
||||
|
||||
boolean loadTestDataFromFile = convertPropertyToBooleanAndWriteBack(LOAD_TEST_DATA_FROM_FILE);
|
||||
this.setLoadTestDataFromFile(loadTestDataFromFile);
|
||||
|
@ -37,7 +37,7 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
|
||||
public static final String USE_ABSTRACTION_FOR_FILES = "useAbstractionForFiles";
|
||||
|
||||
@Setter protected boolean addConsumesProducesJson = true;
|
||||
@Setter protected boolean addConsumesProducesJson = false;
|
||||
|
||||
@Setter protected boolean generateSpringApplication = false;
|
||||
|
||||
@ -137,21 +137,10 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(ADD_CONSUMES_PRODUCES_JSON)) {
|
||||
this.setAddConsumesProducesJson(convertPropertyToBooleanAndWriteBack(ADD_CONSUMES_PRODUCES_JSON));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) {
|
||||
this.setUseGenericResponse(convertPropertyToBoolean(USE_GENERIC_RESPONSE));
|
||||
}
|
||||
|
||||
if (useGenericResponse) {
|
||||
writePropertyBack(USE_GENERIC_RESPONSE, useGenericResponse);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_SPRING_APPLICATION)) {
|
||||
this.setGenerateSpringApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_APPLICATION));
|
||||
|
||||
convertPropertyToBooleanAndWriteBack(ADD_CONSUMES_PRODUCES_JSON, this::setAddConsumesProducesJson);
|
||||
convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE, this::setUseGenericResponse);
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_APPLICATION, this::setGenerateSpringApplication);
|
||||
if (generateSpringApplication) {
|
||||
this.setUseSwaggerFeature(convertPropertyToBooleanAndWriteBack(USE_SWAGGER_FEATURE));
|
||||
this.setUseSwaggerUI(convertPropertyToBooleanAndWriteBack(USE_SWAGGER_UI));
|
||||
|
||||
@ -172,25 +161,13 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
this.setGenerateSpringBootApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_BOOT_APPLICATION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) {
|
||||
boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack(
|
||||
GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR);
|
||||
this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp);
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, this::setGenerateJbossDeploymentDescriptor);
|
||||
|
||||
if (additionalProperties.containsKey(USE_ANNOTATED_BASE_PATH)) {
|
||||
boolean useAnnotatedBasePathProp = convertPropertyToBooleanAndWriteBack(USE_ANNOTATED_BASE_PATH);
|
||||
this.setUseAnnotatedBasePath(useAnnotatedBasePathProp);
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_ANNOTATED_BASE_PATH, this::setUseAnnotatedBasePath);
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_NON_SPRING_APPLICATION)) {
|
||||
boolean generateNonSpringApplication = convertPropertyToBooleanAndWriteBack(GENERATE_NON_SPRING_APPLICATION);
|
||||
this.setGenerateNonSpringApplication(generateNonSpringApplication);
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_NON_SPRING_APPLICATION, this::setGenerateNonSpringApplication);
|
||||
|
||||
if (additionalProperties.containsKey(USE_ABSTRACTION_FOR_FILES)) {
|
||||
this.setUseAbstractionForFiles(convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES));
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES, this::setUseAbstractionForFiles);
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
@ -254,7 +231,7 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
model.imports.remove("ToStringSerializer");
|
||||
|
||||
//Add imports for Jackson when model has inner enum
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
if (isJackson()) {
|
||||
if (Boolean.FALSE.equals(model.isEnum) && Boolean.TRUE.equals(model.hasEnums)) {
|
||||
model.imports.add("JsonCreator");
|
||||
model.imports.add("JsonValue");
|
||||
|
@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.OptionalFeatures;
|
||||
|
@ -116,13 +116,13 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
@Setter protected boolean doNotUseRx = true;
|
||||
@Setter protected boolean usePlayWS = false;
|
||||
@Setter protected String microprofileFramework = MICROPROFILE_DEFAULT;
|
||||
@Setter protected String microprofileRestClientVersion = MICROPROFILE_REST_CLIENT_DEFAULT_VERSION;
|
||||
@Setter protected boolean microprofileMutiny = false;
|
||||
@Setter protected String configKey = null;
|
||||
@Setter(AccessLevel.PRIVATE) protected boolean configKeyFromClassName = false;
|
||||
|
||||
@Setter protected boolean asyncNative = false;
|
||||
@Setter protected boolean parcelableModel = false;
|
||||
@Setter protected boolean useBeanValidation = false;
|
||||
@Setter protected boolean performBeanValidation = false;
|
||||
@Setter protected boolean useGzipFeature = false;
|
||||
@Setter protected boolean useRuntimeException = false;
|
||||
@ -320,73 +320,51 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
dateLibrary = "legacy";
|
||||
}
|
||||
super.processOpts();
|
||||
// default jackson unless overriden by setSerializationLibrary
|
||||
this.jackson = !additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY) || SERIALIZATION_LIBRARY_JACKSON.equals(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP)) {
|
||||
setUseOneOfDiscriminatorLookup(convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, useOneOfDiscriminatorLookup);
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup);
|
||||
|
||||
// RxJava
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA2) && additionalProperties.containsKey(USE_RX_JAVA3)) {
|
||||
LOGGER.warn("You specified all RxJava versions 2 and 3 but they are mutually exclusive. Defaulting to v3.");
|
||||
this.setUseRxJava3(Boolean.parseBoolean(additionalProperties.get(USE_RX_JAVA3).toString()));
|
||||
} else {
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA2) && additionalProperties.containsKey(USE_RX_JAVA3)) {
|
||||
LOGGER.warn("You specified both RxJava versions 2 and 3 but they are mutually exclusive. Defaulting to v3.");
|
||||
this.setUseRxJava3(Boolean.parseBoolean(additionalProperties.get(USE_RX_JAVA3).toString()));
|
||||
convertPropertyToBooleanAndWriteBack(USE_RX_JAVA3, this::setUseRxJava3);
|
||||
writePropertyBack(USE_RX_JAVA2, false);
|
||||
} else {
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA2)) {
|
||||
this.setUseRxJava2(Boolean.parseBoolean(additionalProperties.get(USE_RX_JAVA2).toString()));
|
||||
}
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA3)) {
|
||||
this.setUseRxJava3(Boolean.parseBoolean(additionalProperties.get(USE_RX_JAVA3).toString()));
|
||||
}
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_RX_JAVA3, this::setUseRxJava3);
|
||||
convertPropertyToBooleanAndWriteBack(USE_RX_JAVA2, this::setUseRxJava2);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER)) {
|
||||
this.setUseSingleRequestParameter(convertPropertyToBoolean(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER));
|
||||
}
|
||||
writePropertyBack(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, getUseSingleRequestParameter());
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, this::setUseSingleRequestParameter);
|
||||
|
||||
if (!useRxJava && !useRxJava2 && !useRxJava3) {
|
||||
additionalProperties.put(DO_NOT_USE_RX, true);
|
||||
}
|
||||
|
||||
// Java Play
|
||||
if (additionalProperties.containsKey(USE_PLAY_WS)) {
|
||||
this.setUsePlayWS(Boolean.parseBoolean(additionalProperties.get(USE_PLAY_WS).toString()));
|
||||
}
|
||||
additionalProperties.put(USE_PLAY_WS, usePlayWS);
|
||||
convertPropertyToBooleanAndWriteBack(USE_PLAY_WS, this::setUsePlayWS);
|
||||
|
||||
// Microprofile framework
|
||||
if (additionalProperties.containsKey(MICROPROFILE_FRAMEWORK)) {
|
||||
if (!MICROPROFILE_KUMULUZEE.equals(microprofileFramework)) {
|
||||
throw new RuntimeException("Invalid microprofileFramework '" + microprofileFramework + "'. Must be 'kumuluzee' or none.");
|
||||
}
|
||||
this.setMicroprofileFramework(additionalProperties.get(MICROPROFILE_FRAMEWORK).toString());
|
||||
// this.setMicroprofileFramework(additionalProperties.get(MICROPROFILE_FRAMEWORK).toString());
|
||||
}
|
||||
additionalProperties.put(MICROPROFILE_FRAMEWORK, microprofileFramework);
|
||||
convertPropertyToStringAndWriteBack(MICROPROFILE_FRAMEWORK, this::setMicroprofileFramework);
|
||||
|
||||
if (additionalProperties.containsKey(MICROPROFILE_MUTINY)) {
|
||||
this.setMicroprofileMutiny(convertPropertyToBooleanAndWriteBack(MICROPROFILE_MUTINY));
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(MICROPROFILE_MUTINY, this::setMicroprofileMutiny);
|
||||
|
||||
if (!additionalProperties.containsKey(MICROPROFILE_REST_CLIENT_VERSION)) {
|
||||
additionalProperties.put(MICROPROFILE_REST_CLIENT_VERSION, MICROPROFILE_REST_CLIENT_DEFAULT_VERSION);
|
||||
} else {
|
||||
String mpRestClientVersion = (String) additionalProperties.get(MICROPROFILE_REST_CLIENT_VERSION);
|
||||
if (!mpRestClientVersions.containsKey(mpRestClientVersion)) {
|
||||
convertPropertyToStringAndWriteBack(MICROPROFILE_REST_CLIENT_VERSION, value->microprofileRestClientVersion=value);
|
||||
if (!mpRestClientVersions.containsKey(microprofileRestClientVersion)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(Locale.ROOT,
|
||||
"Version %s of MicroProfile Rest Client is not supported or incorrect. Supported versions are %s",
|
||||
mpRestClientVersion,
|
||||
microprofileRestClientVersion,
|
||||
String.join(", ", mpRestClientVersions.keySet())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!additionalProperties.containsKey("rootJavaEEPackage")) {
|
||||
String mpRestClientVersion = (String) additionalProperties.get(MICROPROFILE_REST_CLIENT_VERSION);
|
||||
if (mpRestClientVersions.containsKey(mpRestClientVersion)) {
|
||||
@ -396,76 +374,25 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_KEY)) {
|
||||
this.setConfigKey(additionalProperties.get(CONFIG_KEY).toString());
|
||||
} else if (additionalProperties.containsKey(CONFIG_KEY_FROM_CLASS_NAME)) {
|
||||
this.setConfigKeyFromClassName(Boolean.parseBoolean(additionalProperties.get(CONFIG_KEY_FROM_CLASS_NAME).toString()));
|
||||
convertPropertyToStringAndWriteBack(CONFIG_KEY, this::setConfigKey);
|
||||
} else {
|
||||
convertPropertyToBooleanAndWriteBack(CONFIG_KEY_FROM_CLASS_NAME, this::setConfigKeyFromClassName);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ASYNC_NATIVE)) {
|
||||
this.setAsyncNative(convertPropertyToBooleanAndWriteBack(ASYNC_NATIVE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(PARCELABLE_MODEL)) {
|
||||
this.setParcelableModel(Boolean.parseBoolean(additionalProperties.get(PARCELABLE_MODEL).toString()));
|
||||
}
|
||||
// put the boolean value back to PARCELABLE_MODEL in additionalProperties
|
||||
additionalProperties.put(PARCELABLE_MODEL, parcelableModel);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(PERFORM_BEANVALIDATION)) {
|
||||
this.setPerformBeanValidation(convertPropertyToBooleanAndWriteBack(PERFORM_BEANVALIDATION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_GZIP_FEATURE)) {
|
||||
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_RUNTIME_EXCEPTION)) {
|
||||
this.setUseRuntimeException(convertPropertyToBooleanAndWriteBack(USE_RUNTIME_EXCEPTION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_REFLECTION_EQUALS_HASHCODE)) {
|
||||
this.setUseReflectionEqualsHashCode(convertPropertyToBooleanAndWriteBack(USE_REFLECTION_EQUALS_HASHCODE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CASE_INSENSITIVE_RESPONSE_HEADERS)) {
|
||||
this.setUseReflectionEqualsHashCode(convertPropertyToBooleanAndWriteBack(CASE_INSENSITIVE_RESPONSE_HEADERS));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_ABSTRACTION_FOR_FILES)) {
|
||||
this.setUseAbstractionForFiles(convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(DYNAMIC_OPERATIONS)) {
|
||||
this.setDynamicOperations(Boolean.parseBoolean(additionalProperties.get(DYNAMIC_OPERATIONS).toString()));
|
||||
}
|
||||
additionalProperties.put(DYNAMIC_OPERATIONS, dynamicOperations);
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_STREAMING)) {
|
||||
this.setSupportStreaming(Boolean.parseBoolean(additionalProperties.get(SUPPORT_STREAMING).toString()));
|
||||
}
|
||||
additionalProperties.put(SUPPORT_STREAMING, supportStreaming);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT)) {
|
||||
this.setWithAWSV4Signature(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT).toString()));
|
||||
}
|
||||
additionalProperties.put(CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT, withAWSV4Signature);
|
||||
|
||||
if (additionalProperties.containsKey(GRADLE_PROPERTIES)) {
|
||||
this.setGradleProperties(additionalProperties.get(GRADLE_PROPERTIES).toString());
|
||||
}
|
||||
additionalProperties.put(GRADLE_PROPERTIES, gradleProperties);
|
||||
|
||||
if (additionalProperties.containsKey(ERROR_OBJECT_TYPE)) {
|
||||
this.setErrorObjectType(additionalProperties.get(ERROR_OBJECT_TYPE).toString());
|
||||
}
|
||||
additionalProperties.put(ERROR_OBJECT_TYPE, errorObjectType);
|
||||
if (additionalProperties.containsKey(WEBCLIENT_BLOCKING_OPERATIONS)) {
|
||||
this.webclientBlockingOperations = Boolean.parseBoolean(additionalProperties.get(WEBCLIENT_BLOCKING_OPERATIONS).toString());
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(ASYNC_NATIVE, this::setAsyncNative);
|
||||
convertPropertyToBooleanAndWriteBack(PARCELABLE_MODEL, this::setParcelableModel);
|
||||
convertPropertyToBooleanAndWriteBack(PERFORM_BEANVALIDATION, this::setPerformBeanValidation);
|
||||
convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE, this::setUseGzipFeature);
|
||||
convertPropertyToBooleanAndWriteBack(USE_RUNTIME_EXCEPTION, this::setUseRuntimeException);
|
||||
convertPropertyToBooleanAndWriteBack(USE_REFLECTION_EQUALS_HASHCODE, this::setUseReflectionEqualsHashCode);
|
||||
convertPropertyToBooleanAndWriteBack(CASE_INSENSITIVE_RESPONSE_HEADERS, this::setUseReflectionEqualsHashCode);
|
||||
convertPropertyToBooleanAndWriteBack(USE_ABSTRACTION_FOR_FILES, this::setUseAbstractionForFiles);
|
||||
convertPropertyToBooleanAndWriteBack(DYNAMIC_OPERATIONS, this::setDynamicOperations);
|
||||
convertPropertyToBooleanAndWriteBack(SUPPORT_STREAMING, this::setSupportStreaming);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT, this::setWithAWSV4Signature);
|
||||
convertPropertyToStringAndWriteBack(GRADLE_PROPERTIES, this::setGradleProperties);
|
||||
convertPropertyToStringAndWriteBack(ERROR_OBJECT_TYPE, this::setErrorObjectType);
|
||||
convertPropertyToBooleanAndWriteBack(WEBCLIENT_BLOCKING_OPERATIONS, op -> webclientBlockingOperations=op);
|
||||
|
||||
// add URL query deepObject support to native, apache-httpclient by default
|
||||
if (!additionalProperties.containsKey(SUPPORT_URL_QUERY)) {
|
||||
@ -477,26 +404,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
additionalProperties.put(SUPPORT_URL_QUERY, Boolean.parseBoolean(additionalProperties.get(SUPPORT_URL_QUERY).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_CLIENT_AS_BEAN)) {
|
||||
this.setGenerateClientAsBean(convertPropertyToBooleanAndWriteBack(GENERATE_CLIENT_AS_BEAN));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_ENUM_CASE_INSENSITIVE)) {
|
||||
this.setUseEnumCaseInsensitive(Boolean.parseBoolean(additionalProperties.get(USE_ENUM_CASE_INSENSITIVE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY)) {
|
||||
this.setMaxAttemptsForRetry(Integer.parseInt(additionalProperties.get(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY).toString()));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY, maxAttemptsForRetry);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.WAIT_TIME_OF_THREAD)) {
|
||||
this.setWaitTimeMillis(Long.parseLong((additionalProperties.get(CodegenConstants.WAIT_TIME_OF_THREAD).toString())));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.WAIT_TIME_OF_THREAD, waitTimeMillis);
|
||||
}
|
||||
writePropertyBack(USE_ENUM_CASE_INSENSITIVE, useEnumCaseInsensitive);
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_CLIENT_AS_BEAN, this::setGenerateClientAsBean);
|
||||
convertPropertyToBooleanAndWriteBack(USE_ENUM_CASE_INSENSITIVE, this::setUseEnumCaseInsensitive);
|
||||
convertPropertyToTypeAndWriteBack(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY, Integer::parseInt, this::setMaxAttemptsForRetry);
|
||||
convertPropertyToTypeAndWriteBack(CodegenConstants.WAIT_TIME_OF_THREAD, Long::parseLong, this::setWaitTimeMillis);
|
||||
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
final String apiFolder = (sourceFolder + '/' + apiPackage).replace(".", "/");
|
||||
@ -556,9 +467,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
"BeanValidationException.java"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) {
|
||||
setSerializationLibrary(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY).toString());
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SERIALIZATION_LIBRARY, this::setSerializationLibrary);
|
||||
|
||||
//TODO: add auto-generated doc to feign
|
||||
if (FEIGN.equals(getLibrary())) {
|
||||
@ -706,8 +615,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
} else if (MICROPROFILE.equals(getLibrary())) {
|
||||
supportingFiles.clear(); // Don't need extra files provided by Java Codegen
|
||||
String apiExceptionFolder = (sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||
String mpRestClientVersion = (String) additionalProperties.get(MICROPROFILE_REST_CLIENT_VERSION);
|
||||
String pomTemplate = mpRestClientVersions.get(mpRestClientVersion).pomTemplate;
|
||||
String pomTemplate = mpRestClientVersions.get(microprofileRestClientVersion).pomTemplate;
|
||||
supportingFiles.add(new SupportingFile(pomTemplate, "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("api_exception.mustache", apiExceptionFolder, "ApiException.java"));
|
||||
@ -725,7 +633,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
supportingFiles.add(new SupportingFile("kumuluzee.beans.xml.mustache", "src/main/resources/META-INF", "beans.xml"));
|
||||
}
|
||||
|
||||
if ("3.0".equals(mpRestClientVersion)) {
|
||||
if ("3.0".equals(microprofileRestClientVersion)) {
|
||||
additionalProperties.put("microprofile3", true);
|
||||
}
|
||||
} else if (APACHE.equals(getLibrary())) {
|
||||
@ -1211,10 +1119,13 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
public void setSerializationLibrary(String serializationLibrary) {
|
||||
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
|
||||
this.jackson = true;
|
||||
} else if (SERIALIZATION_LIBRARY_GSON.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_GSON;
|
||||
this.jackson = false;
|
||||
} else if (SERIALIZATION_LIBRARY_JSONB.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JSONB;
|
||||
this.jackson = false;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected serializationLibrary value: " + serializationLibrary);
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ public class JavaHelidonClientCodegen extends JavaHelidonCommonCodegen {
|
||||
public static final String CONFIG_KEY = "configKey";
|
||||
|
||||
@Setter protected String configKey = null;
|
||||
@Setter protected boolean useBeanValidation = false;
|
||||
@Setter protected boolean performBeanValidation = false;
|
||||
@Setter protected boolean useGzipFeature = false;
|
||||
protected boolean caseInsensitiveResponseHeaders = false;
|
||||
@ -174,13 +173,9 @@ public class JavaHelidonClientCodegen extends JavaHelidonCommonCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY)) {
|
||||
setSerializationLibrary(additionalProperties.get(SERIALIZATION_LIBRARY).toString());
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(SERIALIZATION_LIBRARY, this::setSerializationLibrary);
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_KEY)) {
|
||||
setConfigKey(additionalProperties.get(CONFIG_KEY).toString());
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(CONFIG_KEY, this::setConfigKey);
|
||||
|
||||
String invokerPath = invokerPackage.replace('.', File.separatorChar);
|
||||
invokerFolder = Paths.get(sourceFolder, invokerPath);
|
||||
@ -469,8 +464,10 @@ public class JavaHelidonClientCodegen extends JavaHelidonCommonCodegen {
|
||||
public void setSerializationLibrary(String serializationLibrary) {
|
||||
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
|
||||
this.jackson = true;
|
||||
} else if (SERIALIZATION_LIBRARY_JSONB.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JSONB;
|
||||
this.jackson = false;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected serializationLibrary value: " + serializationLibrary);
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
public static final String USE_ABSTRACT_CLASS = "useAbstractClass";
|
||||
public static final String GRADLE_PROJECT = "gradleProject";
|
||||
|
||||
protected boolean useBeanValidation = true;
|
||||
protected String implFolder = "src/main/java";
|
||||
@Getter protected String serializationLibrary = null;
|
||||
|
||||
@ -71,6 +70,7 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
|
||||
modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));
|
||||
|
||||
this.useBeanValidation = true;
|
||||
outputFolder = "generated-code" + File.separator + "java";
|
||||
embeddedTemplateDir = templateDir = "java-helidon" + File.separator + "server";
|
||||
invokerPackage = "org.openapitools.server";
|
||||
@ -150,36 +150,19 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
List<SupportingFile> unmodifiable = new ArrayList<>();
|
||||
unmodifiable.add(openApiFile);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
importMapping.put("ObjectMapper", "com.fasterxml.jackson.databind.ObjectMapper");
|
||||
importMapping.put("Jsonb", rootJavaEEPackage() + ".json.bind.Jsonb");
|
||||
importMapping.put("JsonbBuilder", rootJavaEEPackage() + ".json.bind.JsonbBuilder");
|
||||
|
||||
if (additionalProperties.containsKey(USE_ABSTRACT_CLASS)) {
|
||||
useAbstractClass = Boolean.parseBoolean(additionalProperties.get(USE_ABSTRACT_CLASS).toString());
|
||||
}
|
||||
if (!useAbstractClass) {
|
||||
additionalProperties.remove(USE_ABSTRACT_CLASS);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GRADLE_PROJECT)) {
|
||||
gradleProject = Boolean.parseBoolean(additionalProperties.get(GRADLE_PROJECT).toString());
|
||||
}
|
||||
if (!gradleProject) {
|
||||
additionalProperties.remove(GRADLE_PROJECT);
|
||||
} else {
|
||||
convertPropertyToBooleanAndWriteBack(USE_ABSTRACT_CLASS, value -> useAbstractClass = value);
|
||||
convertPropertyToBooleanAndWriteBack(GRADLE_PROJECT, value -> gradleProject = value);
|
||||
if (gradleProject) {
|
||||
modifiable.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
modifiable.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
modifiable.remove(pomFile);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) {
|
||||
setSerializationLibrary(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY).toString());
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SERIALIZATION_LIBRARY, this::setSerializationLibrary);
|
||||
|
||||
String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
|
||||
@ -276,7 +259,7 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation codegenOperation = super.fromOperation(path, httpMethod, operation, servers);
|
||||
if (HELIDON_SE.equals(getLibrary())) {
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
if (isJackson()) {
|
||||
codegenOperation.imports.add("ObjectMapper");
|
||||
}
|
||||
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JSONB)) {
|
||||
@ -353,7 +336,7 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
|
||||
if (Boolean.TRUE.equals(model.hasEnums)) {
|
||||
// Add imports for Jackson
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
if (isJackson()) {
|
||||
model.imports.add("JsonValue");
|
||||
model.imports.add("JsonCreator");
|
||||
}
|
||||
@ -375,12 +358,6 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
return "Generates a Java Helidon Server application.";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPerformBeanValidation(boolean performBeanValidation) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
@ -389,8 +366,10 @@ public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
public void setSerializationLibrary(String serializationLibrary) {
|
||||
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
|
||||
this.jackson = true;
|
||||
} else if (SERIALIZATION_LIBRARY_JSONB.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JSONB;
|
||||
this.jackson = false;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected serializationLibrary value: " + serializationLibrary);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class JavaInflectorServerCodegen extends AbstractJavaCodegen {
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
// java inflector uses the jackson lib
|
||||
additionalProperties.put(JACKSON, "true");
|
||||
this.jackson = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,13 +69,6 @@ public class JavaJAXRSCXFCDIServerCodegen extends JavaJAXRSSpecServerCodegen imp
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
// POM
|
||||
|
@ -56,8 +56,8 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
private boolean useMicroProfileOpenAPIAnnotations = false;
|
||||
private boolean useMutiny = false;
|
||||
|
||||
@Setter
|
||||
protected boolean useGzipFeature = false;
|
||||
private boolean useJackson = false;
|
||||
/**
|
||||
* -- SETTER --
|
||||
* Location where the file containing the spec will be generated in the output folder.
|
||||
@ -133,54 +133,26 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
if (additionalProperties.containsKey(GENERATE_POM)) {
|
||||
generatePom = Boolean.parseBoolean(additionalProperties.get(GENERATE_POM).toString());
|
||||
}
|
||||
if (additionalProperties.containsKey(INTERFACE_ONLY)) {
|
||||
interfaceOnly = Boolean.parseBoolean(additionalProperties.get(INTERFACE_ONLY).toString());
|
||||
if (!interfaceOnly) {
|
||||
additionalProperties.remove(INTERFACE_ONLY);
|
||||
}
|
||||
}
|
||||
if (additionalProperties.containsKey(RETURN_RESPONSE)) {
|
||||
returnResponse = Boolean.parseBoolean(additionalProperties.get(RETURN_RESPONSE).toString());
|
||||
if (!returnResponse) {
|
||||
additionalProperties.remove(RETURN_RESPONSE);
|
||||
}
|
||||
}
|
||||
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
|
||||
supportAsync = Boolean.parseBoolean(additionalProperties.get(SUPPORT_ASYNC).toString());
|
||||
if (!supportAsync) {
|
||||
additionalProperties.remove(SUPPORT_ASYNC);
|
||||
} else {
|
||||
// java8 tag has been deprecated
|
||||
//setJava8ModeAndAdditionalProperties(true);
|
||||
}
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_POM, value -> generatePom = value);
|
||||
|
||||
convertPropertyToBooleanAndWriteBack(INTERFACE_ONLY, value -> interfaceOnly = value);
|
||||
convertPropertyToBooleanAndWriteBack(RETURN_RESPONSE, value -> returnResponse = value);
|
||||
convertPropertyToBooleanAndWriteBack(SUPPORT_ASYNC, this::setSupportAsync);
|
||||
if (QUARKUS_LIBRARY.equals(library) || THORNTAIL_LIBRARY.equals(library) || HELIDON_LIBRARY.equals(library) || OPEN_LIBERTY_LIBRARY.equals(library) || KUMULUZEE_LIBRARY.equals(library)) {
|
||||
useSwaggerAnnotations = false;
|
||||
} else {
|
||||
if (additionalProperties.containsKey(USE_SWAGGER_ANNOTATIONS)) {
|
||||
useSwaggerAnnotations = Boolean.parseBoolean(additionalProperties.get(USE_SWAGGER_ANNOTATIONS).toString());
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_ANNOTATIONS, value -> useSwaggerAnnotations = value);
|
||||
}
|
||||
if (KUMULUZEE_LIBRARY.equals(library)){
|
||||
super.setSourceFolder("src/main/java");
|
||||
}
|
||||
writePropertyBack(USE_SWAGGER_ANNOTATIONS, useSwaggerAnnotations);
|
||||
|
||||
if (QUARKUS_LIBRARY.equals(library)) {
|
||||
if (additionalProperties.containsKey(USE_MICROPROFILE_OPENAPI_ANNOTATIONS)) {
|
||||
useMicroProfileOpenAPIAnnotations = Boolean.parseBoolean(additionalProperties.get(USE_MICROPROFILE_OPENAPI_ANNOTATIONS).toString());
|
||||
}
|
||||
writePropertyBack(USE_MICROPROFILE_OPENAPI_ANNOTATIONS, useMicroProfileOpenAPIAnnotations);
|
||||
convertPropertyToBooleanAndWriteBack(USE_MICROPROFILE_OPENAPI_ANNOTATIONS, value -> useMicroProfileOpenAPIAnnotations = value);
|
||||
}
|
||||
|
||||
if (QUARKUS_LIBRARY.equals(library)) {
|
||||
if (additionalProperties.containsKey(USE_MUTINY)) {
|
||||
useMutiny = Boolean.parseBoolean(additionalProperties.get(USE_MUTINY).toString());
|
||||
}
|
||||
writePropertyBack(USE_MUTINY, useMutiny);
|
||||
convertPropertyToBooleanAndWriteBack(USE_MUTINY, value -> useMutiny = value);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(OPEN_API_SPEC_FILE_LOCATION)) {
|
||||
@ -193,8 +165,6 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
additionalProperties.put(OPEN_API_SPEC_FILE_LOCATION, openApiSpecFileLocation);
|
||||
|
||||
useJackson = convertPropertyToBoolean(JACKSON);
|
||||
|
||||
if (interfaceOnly) {
|
||||
// Change default artifactId if generating interfaces only, before command line options are applied in base class.
|
||||
artifactId = "openapi-jaxrs-client";
|
||||
@ -264,12 +234,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
supportingFiles.add(new SupportingFile("config.yaml.mustache", "src/main/resources", "config.yaml"));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_GZIP_FEATURE)) {
|
||||
useGzipFeature = Boolean.parseBoolean(additionalProperties.get(USE_GZIP_FEATURE).toString());
|
||||
if (!useGzipFeature) {
|
||||
additionalProperties.remove(USE_GZIP_FEATURE);
|
||||
}
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE, this::setUseGzipFeature);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -284,7 +249,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
codegenModel.imports.remove("ApiModelProperty");
|
||||
codegenModel.imports.remove("ApiModel");
|
||||
}
|
||||
if (!useJackson) {
|
||||
if (!jackson) {
|
||||
codegenModel.imports.remove("JsonSerialize");
|
||||
codegenModel.imports.remove("ToStringSerializer");
|
||||
codegenModel.imports.remove("JsonValue");
|
||||
|
@ -115,10 +115,7 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.IMPL_FOLDER, value -> implFolder = value);
|
||||
if ("joda".equals(dateLibrary)) {
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
|
||||
|
@ -92,9 +92,7 @@ public class JavaMSF4JServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
setLibrary(DEFAULT_MSF4J_LIBRARY);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.IMPL_FOLDER, value -> implFolder = value);
|
||||
|
||||
if ("joda".equals(dateLibrary)) {
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
|
@ -58,7 +58,6 @@ public abstract class JavaMicronautAbstractCodegen extends AbstractJavaCodegen i
|
||||
protected final Logger LOGGER = LoggerFactory.getLogger(JavaMicronautAbstractCodegen.class);
|
||||
|
||||
protected String title;
|
||||
@Getter protected boolean useBeanValidation;
|
||||
@Getter protected boolean useOptional;
|
||||
@Getter @Setter
|
||||
protected boolean visitable;
|
||||
@ -226,10 +225,6 @@ public abstract class JavaMicronautAbstractCodegen extends AbstractJavaCodegen i
|
||||
}
|
||||
|
||||
// Get boolean properties
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(USE_OPTIONAL)) {
|
||||
this.setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
|
||||
@ -319,6 +314,7 @@ public abstract class JavaMicronautAbstractCodegen extends AbstractJavaCodegen i
|
||||
setSerializationLibrary((String) additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));
|
||||
}
|
||||
additionalProperties.put(this.serializationLibrary, true);
|
||||
this.jackson = JACKSON.equals(this.serializationLibrary);
|
||||
|
||||
// Add all the supporting files
|
||||
String resourceFolder = projectFolder + "/resources";
|
||||
@ -427,11 +423,6 @@ public abstract class JavaMicronautAbstractCodegen extends AbstractJavaCodegen i
|
||||
return toModelName(name) + "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseOptional(boolean useOptional) {
|
||||
this.useOptional = useOptional;
|
||||
|
@ -66,22 +66,14 @@ public class JavaMicronautClientCodegen extends JavaMicronautAbstractCodegen {
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(OPT_CONFIGURE_AUTH)) {
|
||||
this.configureAuthorization = convertPropertyToBoolean(OPT_CONFIGURE_AUTH);
|
||||
}
|
||||
writePropertyBack(OPT_CONFIGURE_AUTH, configureAuthorization);
|
||||
convertPropertyToBooleanAndWriteBack(OPT_CONFIGURE_AUTH, value -> this.configureAuthorization = value);
|
||||
|
||||
// Write property that is present in server
|
||||
writePropertyBack(OPT_USE_AUTH, true);
|
||||
|
||||
writePropertyBack(OPT_CONFIGURE_AUTH_FILTER_PATTERN, false);
|
||||
writePropertyBack(OPT_CONFIGURE_CLIENT_ID, false);
|
||||
|
||||
if(additionalProperties.containsKey(BASE_PATH_SEPARATOR)) {
|
||||
basePathSeparator = additionalProperties.get(BASE_PATH_SEPARATOR).toString();
|
||||
}
|
||||
writePropertyBack(BASE_PATH_SEPARATOR, basePathSeparator);
|
||||
convertPropertyToStringAndWriteBack(BASE_PATH_SEPARATOR, this::setBasePathSeparator);
|
||||
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen {
|
||||
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
|
||||
additionalProperties.put(JACKSON, "true");
|
||||
this.jackson = true;
|
||||
|
||||
this.cliOptions.add(new CliOption("basePackage", "base package for java source code"));
|
||||
this.cliOptions.add(new CliOption("serviceName", "Service Name"));
|
||||
@ -130,53 +130,18 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen {
|
||||
this.additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
}
|
||||
if (this.additionalProperties.containsKey("groupId")) {
|
||||
this.setGroupId((String) this.additionalProperties.get("groupId"));
|
||||
} else {
|
||||
// not set, use to be passed to template
|
||||
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||
}
|
||||
if (this.additionalProperties.containsKey("artifactId")) {
|
||||
this.setArtifactId((String) this.additionalProperties.get("artifactId"));
|
||||
} else {
|
||||
// not set, use to be passed to template
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||
}
|
||||
if (this.additionalProperties.containsKey("artifactVersion")) {
|
||||
this.setArtifactVersion((String) this.additionalProperties.get("artifactVersion"));
|
||||
} else {
|
||||
// not set, use to be passed to template
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
}
|
||||
if (this.additionalProperties.containsKey("serviceName")) {
|
||||
this.setServiceName((String) this.additionalProperties.get("serviceName"));
|
||||
} else {
|
||||
// not set, use to be passed to template
|
||||
additionalProperties.put("serviceName", serviceName);
|
||||
}
|
||||
convertPropertyToStringAndWriteBack("groupId", this::setGroupId);
|
||||
|
||||
if (this.additionalProperties.containsKey(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING)) {
|
||||
this.setSerializeBigDecimalAsString(Boolean.parseBoolean(
|
||||
this.additionalProperties.get(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING).toString()));
|
||||
}
|
||||
if (this.additionalProperties.containsKey(CodegenConstants.SERIALIZABLE_MODEL)) {
|
||||
this.setSerializableModel(
|
||||
Boolean.valueOf(this.additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL).toString()));
|
||||
}
|
||||
if (this.additionalProperties.containsKey(TITLE)) {
|
||||
this.setTitle((String) this.additionalProperties.get(TITLE));
|
||||
}
|
||||
convertPropertyToStringAndWriteBack("artifactId", this::setArtifactId);
|
||||
convertPropertyToStringAndWriteBack("artifactVersion", this::setArtifactVersion);
|
||||
convertPropertyToStringAndWriteBack("serviceName", this::setServiceName);
|
||||
convertPropertyToBooleanAndWriteBack(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, this::setSerializeBigDecimalAsString);
|
||||
convertPropertyToStringAndWriteBack(CodegenConstants.SERIALIZABLE_MODEL, this::setTitle);
|
||||
this.additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
|
||||
|
||||
if (this.additionalProperties.containsKey(EUREKA_URI)) {
|
||||
this.setEurekaUri((String) this.additionalProperties.get(EUREKA_URI));
|
||||
}
|
||||
if (this.additionalProperties.containsKey(ZIPKIN_URI)) {
|
||||
this.setZipkinUri((String) this.additionalProperties.get(ZIPKIN_URI));
|
||||
}
|
||||
if (this.additionalProperties.containsKey(SPRINGADMIN_URI)) {
|
||||
this.setSpringBootAdminUri((String) this.additionalProperties.get(SPRINGADMIN_URI));
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(EUREKA_URI, this::setEurekaUri);
|
||||
convertPropertyToStringAndWriteBack(ZIPKIN_URI, this::setZipkinUri);
|
||||
convertPropertyToStringAndWriteBack(SPRINGADMIN_URI, this::setSpringBootAdminUri);
|
||||
this.additionalProperties.put("java8", true);
|
||||
|
||||
if (this.additionalProperties.containsKey(WITH_XML)) {
|
||||
@ -406,7 +371,7 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
} else { // enum class
|
||||
// Needed imports for Jackson's JsonCreator
|
||||
if (this.additionalProperties.containsKey(JACKSON)) {
|
||||
if (isJackson()) {
|
||||
model.imports.add("JsonCreator");
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
protected String basePackage = "org.openapitools";
|
||||
@Setter protected boolean controllerOnly = false;
|
||||
@Setter protected boolean useInterfaces = true;
|
||||
@Setter protected boolean useBeanValidation = true;
|
||||
@Setter protected boolean handleExceptions = true;
|
||||
@Setter protected boolean wrapCalls = true;
|
||||
@Setter protected boolean useSwaggerUI = true;
|
||||
@ -72,6 +71,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
|
||||
modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));
|
||||
|
||||
useBeanValidation = true;
|
||||
outputFolder = "generated-code/javaPlayFramework";
|
||||
apiTestTemplateFiles.clear();
|
||||
embeddedTemplateDir = templateDir = "JavaPlayFramework";
|
||||
@ -93,7 +93,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
|
||||
additionalProperties.put("java8", true);
|
||||
additionalProperties.put(JACKSON, "true");
|
||||
this.jackson = true;
|
||||
|
||||
cliOptions.add(new CliOption(TITLE, "server title name or client service name").defaultValue(title));
|
||||
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code").defaultValue(getConfigPackage()));
|
||||
@ -133,57 +133,20 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
//TODO: add doc templates
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
convertPropertyToStringAndWriteBack(TITLE, this::setTitle);
|
||||
|
||||
if (additionalProperties.containsKey(TITLE)) {
|
||||
this.setTitle((String) additionalProperties.get(TITLE));
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(CONFIG_PACKAGE, this::setConfigPackage);
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_PACKAGE)) {
|
||||
this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE));
|
||||
} else {
|
||||
additionalProperties.put(CONFIG_PACKAGE, configPackage);
|
||||
}
|
||||
convertPropertyToStringAndWriteBack(BASE_PACKAGE, this::setBasePackage);
|
||||
convertPropertyToBooleanAndWriteBack(CONTROLLER_ONLY, this::setControllerOnly);
|
||||
|
||||
if (additionalProperties.containsKey(BASE_PACKAGE)) {
|
||||
this.setBasePackage((String) additionalProperties.get(BASE_PACKAGE));
|
||||
} else {
|
||||
additionalProperties.put(BASE_PACKAGE, basePackage);
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_INTERFACES, this::setUseInterfaces);
|
||||
|
||||
if (additionalProperties.containsKey(CONTROLLER_ONLY)) {
|
||||
this.setControllerOnly(convertPropertyToBoolean(CONTROLLER_ONLY));
|
||||
}
|
||||
writePropertyBack(CONTROLLER_ONLY, controllerOnly);
|
||||
convertPropertyToBooleanAndWriteBack(HANDLE_EXCEPTIONS, this::setHandleExceptions);
|
||||
convertPropertyToBooleanAndWriteBack(WRAP_CALLS, this::setWrapCalls);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(USE_INTERFACES)) {
|
||||
this.setUseInterfaces(convertPropertyToBoolean(USE_INTERFACES));
|
||||
}
|
||||
writePropertyBack(USE_INTERFACES, useInterfaces);
|
||||
|
||||
if (additionalProperties.containsKey(HANDLE_EXCEPTIONS)) {
|
||||
this.setHandleExceptions(convertPropertyToBoolean(HANDLE_EXCEPTIONS));
|
||||
}
|
||||
writePropertyBack(HANDLE_EXCEPTIONS, handleExceptions);
|
||||
|
||||
if (additionalProperties.containsKey(WRAP_CALLS)) {
|
||||
this.setWrapCalls(convertPropertyToBoolean(WRAP_CALLS));
|
||||
}
|
||||
writePropertyBack(WRAP_CALLS, wrapCalls);
|
||||
|
||||
if (additionalProperties.containsKey(USE_SWAGGER_UI)) {
|
||||
this.setUseSwaggerUI(convertPropertyToBoolean(USE_SWAGGER_UI));
|
||||
}
|
||||
writePropertyBack(USE_SWAGGER_UI, useSwaggerUI);
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_ASYNC)) {
|
||||
this.setSupportAsync(convertPropertyToBoolean(SUPPORT_ASYNC));
|
||||
}
|
||||
writePropertyBack(SUPPORT_ASYNC, supportAsync);
|
||||
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_UI, this::setUseSwaggerUI);
|
||||
convertPropertyToBooleanAndWriteBack(SUPPORT_ASYNC, this::setSupportAsync);
|
||||
|
||||
//We don't use annotation anymore
|
||||
importMapping.remove("ApiModelProperty");
|
||||
|
@ -82,22 +82,9 @@ public class JavaResteasyEapServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) {
|
||||
boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR);
|
||||
this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp);
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, this::setGenerateJbossDeploymentDescriptor);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(USE_SWAGGER_FEATURE)) {
|
||||
this.setUseSwaggerFeature(convertPropertyToBoolean(USE_SWAGGER_FEATURE));
|
||||
}
|
||||
|
||||
writePropertyBack(USE_SWAGGER_FEATURE, useSwaggerFeature);
|
||||
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_FEATURE, this::setUseSwaggerFeature);
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")
|
||||
.doNotOverwrite());
|
||||
|
@ -75,12 +75,7 @@ public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen im
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR)) {
|
||||
boolean generateJbossDeploymentDescriptorProp = convertPropertyToBooleanAndWriteBack(
|
||||
GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR);
|
||||
this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp);
|
||||
}
|
||||
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, this::setGenerateJbossDeploymentDescriptor);
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")
|
||||
.doNotOverwrite());
|
||||
supportingFiles.add(new SupportingFile("gradle.mustache", "", "build.gradle")
|
||||
|
@ -145,10 +145,9 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
@Setter protected boolean async = false;
|
||||
@Setter protected boolean reactive = false;
|
||||
@Setter protected boolean sse = false;
|
||||
@Setter protected String responseWrapper = "";
|
||||
@Setter protected String responseWrapper = null;
|
||||
@Setter protected boolean skipDefaultInterface = false;
|
||||
@Setter protected boolean useTags = false;
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean performBeanValidation = false;
|
||||
@Setter protected boolean apiFirst = false;
|
||||
protected boolean useOptional = false;
|
||||
@ -181,6 +180,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
.includeSchemaSupportFeatures(SchemaSupportFeature.Polymorphism)
|
||||
.excludeParameterFeatures(ParameterFeature.Cookie));
|
||||
|
||||
useBeanValidation = true;
|
||||
outputFolder = "generated-code/javaSpring";
|
||||
embeddedTemplateDir = templateDir = "JavaSpring";
|
||||
apiPackage = "org.openapitools.api";
|
||||
@ -197,7 +197,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
apiTestTemplateFiles.clear(); // TODO: add test template
|
||||
|
||||
// spring uses the jackson lib
|
||||
additionalProperties.put(JACKSON, "true");
|
||||
jackson = true;
|
||||
additionalProperties.put("openbrace", OPEN_BRACE);
|
||||
additionalProperties.put("closebrace", CLOSE_BRACE);
|
||||
|
||||
@ -352,16 +352,10 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
&& additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
// set invokerPackage as basePackage:
|
||||
this.setBasePackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
additionalProperties.put(BASE_PACKAGE, basePackage);
|
||||
LOGGER.info("Set base package to invoker package ({})", basePackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(REQUEST_MAPPING_OPTION)) {
|
||||
RequestMappingMode optValue = RequestMappingMode.valueOf(
|
||||
String.valueOf(additionalProperties.get(REQUEST_MAPPING_OPTION)));
|
||||
setRequestMappingMode(optValue);
|
||||
additionalProperties.remove(REQUEST_MAPPING_OPTION);
|
||||
}
|
||||
convertPropertyToTypeAndWriteBack(REQUEST_MAPPING_OPTION, RequestMappingMode::valueOf, this::setRequestMappingMode);
|
||||
|
||||
useOneOfInterfaces = true;
|
||||
legacyDiscriminatorBehavior = false;
|
||||
@ -400,139 +394,45 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
|
||||
if (additionalProperties.containsKey(TITLE)) {
|
||||
this.setTitle((String) additionalProperties.get(TITLE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_PACKAGE)) {
|
||||
this.setConfigPackage((String) additionalProperties.get(CONFIG_PACKAGE));
|
||||
} else {
|
||||
additionalProperties.put(CONFIG_PACKAGE, configPackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(BASE_PACKAGE)) {
|
||||
this.setBasePackage((String) additionalProperties.get(BASE_PACKAGE));
|
||||
} else {
|
||||
additionalProperties.put(BASE_PACKAGE, basePackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(VIRTUAL_SERVICE)) {
|
||||
this.setVirtualService(Boolean.parseBoolean(additionalProperties.get(VIRTUAL_SERVICE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(INTERFACE_ONLY)) {
|
||||
this.setInterfaceOnly(Boolean.parseBoolean(additionalProperties.get(INTERFACE_ONLY).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_FEIGN_CLIENT_URL)) {
|
||||
this.setUseFeignClientUrl(Boolean.parseBoolean(additionalProperties.get(USE_FEIGN_CLIENT_URL).toString()));
|
||||
}
|
||||
writePropertyBack(USE_FEIGN_CLIENT_URL, useFeignClientUrl);
|
||||
|
||||
if (additionalProperties.containsKey(DELEGATE_PATTERN)) {
|
||||
this.setDelegatePattern(Boolean.parseBoolean(additionalProperties.get(DELEGATE_PATTERN).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SINGLE_CONTENT_TYPES)) {
|
||||
this.setSingleContentTypes(Boolean.parseBoolean(additionalProperties.get(SINGLE_CONTENT_TYPES).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SKIP_DEFAULT_INTERFACE)) {
|
||||
this.setSkipDefaultInterface(
|
||||
Boolean.parseBoolean(additionalProperties.get(SKIP_DEFAULT_INTERFACE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ASYNC)) {
|
||||
this.setAsync(Boolean.parseBoolean(additionalProperties.get(ASYNC).toString()));
|
||||
// fix for issue/1164
|
||||
convertPropertyToBooleanAndWriteBack(ASYNC);
|
||||
}
|
||||
|
||||
convertPropertyToStringAndWriteBack(TITLE, this::setTitle);
|
||||
convertPropertyToStringAndWriteBack(CONFIG_PACKAGE, this::setConfigPackage);
|
||||
convertPropertyToStringAndWriteBack(BASE_PACKAGE, this::setBasePackage);
|
||||
convertPropertyToBooleanAndWriteBack(VIRTUAL_SERVICE, this::setVirtualService);
|
||||
convertPropertyToBooleanAndWriteBack(INTERFACE_ONLY, this::setInterfaceOnly);
|
||||
convertPropertyToBooleanAndWriteBack(USE_FEIGN_CLIENT_URL, this::setUseFeignClientUrl);
|
||||
convertPropertyToBooleanAndWriteBack(DELEGATE_PATTERN, this::setDelegatePattern);
|
||||
convertPropertyToBooleanAndWriteBack(SINGLE_CONTENT_TYPES, this:: setSingleContentTypes);
|
||||
convertPropertyToBooleanAndWriteBack(SKIP_DEFAULT_INTERFACE, this::setSkipDefaultInterface);
|
||||
convertPropertyToBooleanAndWriteBack(ASYNC, this::setAsync);
|
||||
if (additionalProperties.containsKey(REACTIVE)) {
|
||||
if (SPRING_CLOUD_LIBRARY.equals(library)) {
|
||||
throw new IllegalArgumentException("Currently, reactive option doesn't supported by Spring Cloud");
|
||||
}
|
||||
this.setReactive(Boolean.parseBoolean(additionalProperties.get(REACTIVE).toString()));
|
||||
if (additionalProperties.containsKey(SSE)) {
|
||||
this.setSse(Boolean.parseBoolean(additionalProperties.get(SSE).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(RESPONSE_WRAPPER)) {
|
||||
this.setResponseWrapper((String) additionalProperties.get(RESPONSE_WRAPPER));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_TAGS)) {
|
||||
this.setUseTags(Boolean.parseBoolean(additionalProperties.get(USE_TAGS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(PERFORM_BEANVALIDATION)) {
|
||||
this.setPerformBeanValidation(convertPropertyToBoolean(PERFORM_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(PERFORM_BEANVALIDATION, performBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(USE_OPTIONAL)) {
|
||||
this.setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(API_FIRST)) {
|
||||
this.setApiFirst(Boolean.parseBoolean(additionalProperties.get(API_FIRST).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(HATEOAS)) {
|
||||
this.setHateoas(Boolean.parseBoolean(additionalProperties.get(HATEOAS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SPRING_CONTROLLER)) {
|
||||
this.setUseSpringController(convertPropertyToBoolean(SPRING_CONTROLLER));
|
||||
}
|
||||
writePropertyBack(SPRING_CONTROLLER, useSpringController);
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_CONSTRUCTOR_WITH_REQUIRED_ARGS)) {
|
||||
this.generatedConstructorWithRequiredArgs = convertPropertyToBoolean(GENERATE_CONSTRUCTOR_WITH_REQUIRED_ARGS);
|
||||
}
|
||||
writePropertyBack(GENERATE_CONSTRUCTOR_WITH_REQUIRED_ARGS, generatedConstructorWithRequiredArgs);
|
||||
|
||||
if (additionalProperties.containsKey(RETURN_SUCCESS_CODE)) {
|
||||
this.setReturnSuccessCode(Boolean.parseBoolean(additionalProperties.get(RETURN_SUCCESS_CODE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_SWAGGER_UI)) {
|
||||
this.setUseSwaggerUI(convertPropertyToBoolean(USE_SWAGGER_UI));
|
||||
convertPropertyToBooleanAndWriteBack(REACTIVE, this::setReactive);
|
||||
convertPropertyToBooleanAndWriteBack(SSE, this::setSse);
|
||||
}
|
||||
|
||||
convertPropertyToStringAndWriteBack(RESPONSE_WRAPPER, this::setResponseWrapper);
|
||||
convertPropertyToBooleanAndWriteBack(USE_TAGS, this::setUseTags);
|
||||
convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION, this::setUseBeanValidation);
|
||||
convertPropertyToBooleanAndWriteBack(PERFORM_BEANVALIDATION, this::setPerformBeanValidation);
|
||||
convertPropertyToBooleanAndWriteBack(USE_OPTIONAL, this::setUseOptional);
|
||||
convertPropertyToBooleanAndWriteBack(API_FIRST, this::setApiFirst);
|
||||
convertPropertyToBooleanAndWriteBack(HATEOAS, this::setHateoas);
|
||||
convertPropertyToBooleanAndWriteBack(SPRING_CONTROLLER, this::setUseSpringController);
|
||||
convertPropertyToBooleanAndWriteBack(GENERATE_CONSTRUCTOR_WITH_REQUIRED_ARGS, value -> this.generatedConstructorWithRequiredArgs=value);
|
||||
convertPropertyToBooleanAndWriteBack(RETURN_SUCCESS_CODE, this::setReturnSuccessCode);
|
||||
convertPropertyToBooleanAndWriteBack(USE_SWAGGER_UI, this::setUseSwaggerUI);
|
||||
if (getDocumentationProvider().equals(DocumentationProvider.NONE)) {
|
||||
this.setUseSwaggerUI(false);
|
||||
}
|
||||
|
||||
writePropertyBack(USE_SWAGGER_UI, useSwaggerUI);
|
||||
|
||||
if (additionalProperties.containsKey(UNHANDLED_EXCEPTION_HANDLING)) {
|
||||
this.setUnhandledException(
|
||||
Boolean.parseBoolean(additionalProperties.get(UNHANDLED_EXCEPTION_HANDLING).toString()));
|
||||
}
|
||||
additionalProperties.put(UNHANDLED_EXCEPTION_HANDLING, this.isUnhandledException());
|
||||
|
||||
if (additionalProperties.containsKey(USE_RESPONSE_ENTITY)) {
|
||||
this.setUseResponseEntity(
|
||||
Boolean.parseBoolean(additionalProperties.get(USE_RESPONSE_ENTITY).toString()));
|
||||
}
|
||||
writePropertyBack(USE_RESPONSE_ENTITY, useResponseEntity);
|
||||
convertPropertyToBooleanAndWriteBack(UNHANDLED_EXCEPTION_HANDLING, this::setUnhandledException);
|
||||
convertPropertyToBooleanAndWriteBack(USE_RESPONSE_ENTITY, this::setUseResponseEntity);
|
||||
additionalProperties.put("springHttpStatus", new SpringHttpStatusLambda());
|
||||
|
||||
if (additionalProperties.containsKey(USE_ENUM_CASE_INSENSITIVE)) {
|
||||
this.setUseEnumCaseInsensitive(Boolean.parseBoolean(additionalProperties.get(USE_ENUM_CASE_INSENSITIVE).toString()));
|
||||
}
|
||||
writePropertyBack(USE_ENUM_CASE_INSENSITIVE, useEnumCaseInsensitive);
|
||||
|
||||
if (additionalProperties.containsKey(USE_SPRING_BOOT3)) {
|
||||
this.setUseSpringBoot3(convertPropertyToBoolean(USE_SPRING_BOOT3));
|
||||
}
|
||||
convertPropertyToBooleanAndWriteBack(USE_ENUM_CASE_INSENSITIVE, this::setUseEnumCaseInsensitive);
|
||||
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT3, this::setUseSpringBoot3);
|
||||
if (isUseSpringBoot3()) {
|
||||
if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
|
||||
throw new IllegalArgumentException(DocumentationProvider.SPRINGFOX.getPropertyName() + " is not supported with Spring Boot > 3.x");
|
||||
@ -541,16 +441,9 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
throw new IllegalArgumentException(AnnotationLibrary.SWAGGER1.getPropertyName() + " is not supported with Spring Boot > 3.x");
|
||||
}
|
||||
useJakartaEe=true;
|
||||
additionalProperties.put(USE_JAKARTA_EE, useJakartaEe);
|
||||
applyJakartaPackage();
|
||||
}
|
||||
writePropertyBack(USE_SPRING_BOOT3, isUseSpringBoot3());
|
||||
|
||||
if (additionalProperties.containsKey(RESOURCE_FOLDER)) {
|
||||
this.setResourceFolder((String) additionalProperties.get(RESOURCE_FOLDER));
|
||||
}
|
||||
additionalProperties.put(RESOURCE_FOLDER, resourceFolder);
|
||||
|
||||
convertPropertyToStringAndWriteBack(RESOURCE_FOLDER, this::setResourceFolder);
|
||||
|
||||
typeMapping.put("file", "org.springframework.core.io.Resource");
|
||||
importMapping.put("org.springframework.core.io.Resource", "org.springframework.core.io.Resource");
|
||||
@ -561,10 +454,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
importMapping.put("ParameterObject", "org.springdoc.core.annotations.ParameterObject");
|
||||
}
|
||||
|
||||
if (useOptional) {
|
||||
writePropertyBack(USE_OPTIONAL, useOptional);
|
||||
}
|
||||
|
||||
if (interfaceOnly && delegatePattern) {
|
||||
delegateMethod = true;
|
||||
additionalProperties.put("delegate-method", true);
|
||||
@ -1259,11 +1148,6 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPerformBeanValidation(boolean performBeanValidation) {
|
||||
this.performBeanValidation = performBeanValidation;
|
||||
|
@ -20,6 +20,7 @@ import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.api.TemplatingEngineAdapter;
|
||||
import org.openapitools.codegen.api.TemplatingExecutor;
|
||||
import org.slf4j.Logger;
|
||||
@ -28,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@ -64,8 +66,19 @@ public class MustacheEngineAdapter implements TemplatingEngineAdapter {
|
||||
.withLoader(name -> findTemplate(executor, name))
|
||||
.defaultValue("")
|
||||
.compile(executor.getFullTemplateContents(templateFile));
|
||||
StringWriter out = new StringWriter();
|
||||
|
||||
return tmpl.execute(bundle);
|
||||
// the value of bundle[MUSTACHE_PARENT_CONTEXT] is used a parent content in mustache.
|
||||
// See description in https://mustache.github.io/mustache.5.html#Variables
|
||||
// See DefaultCodegen.processOpts() and DefaultCodegen.useCodegenAsMustacheParentContext
|
||||
Object parent = bundle.get(CodegenConstants.MUSTACHE_PARENT_CONTEXT);
|
||||
if (parent == null) {
|
||||
LOGGER.warn("{} not found. super.processOpts needs to be called in processOpts()", CodegenConstants.MUSTACHE_PARENT_CONTEXT);
|
||||
// avoid NPE
|
||||
parent = new Object();
|
||||
}
|
||||
tmpl.execute(bundle, parent, out);
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S108") // catch-all is expected, and is later thrown
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.samskivert.mustache;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Evaluate a mustache variable using the same mustache context as MustacheEngineAdapter.
|
||||
*/
|
||||
public class MustacheEvaluator {
|
||||
private final Template template;
|
||||
private final Template.Context context;
|
||||
|
||||
private MustacheEvaluator(Template.Context context) {
|
||||
this.context = context;
|
||||
this.template = Mustache.compiler().compile(new StringReader(""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mustache context from the additionalProperties.
|
||||
*
|
||||
* @param additionalProperties
|
||||
* @return a mustache evaluator with the context constructed as in MustacheEngineAdapter.
|
||||
*/
|
||||
public static MustacheEvaluator create(Map<String, Object> additionalProperties) {
|
||||
return new MustacheEvaluator(new MustacheTemplateContext(additionalProperties));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the value from the mustache context.
|
||||
*
|
||||
* @param name variable name
|
||||
* @return the value as mustache would see
|
||||
*/
|
||||
public Object getValue(String name) {
|
||||
return template.getValue(context, name, 0, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.samskivert.mustache;
|
||||
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
class MustacheTemplateContext extends Template.Context {
|
||||
MustacheTemplateContext(Object parent) {
|
||||
super(parent, null, 0, false, false);
|
||||
}
|
||||
public MustacheTemplateContext(Map<String, Object> additionalProperties) {
|
||||
super(additionalProperties, new MustacheTemplateContext(additionalProperties.get(CodegenConstants.MUSTACHE_PARENT_CONTEXT)), 0, false, false);
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ package org.openapitools.codegen.config;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
@ -31,8 +32,8 @@ import java.util.Map;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class CodegenConfiguratorTest {
|
||||
private void want(Map<String, Object> additionalProperties, String key, Object expected) {
|
||||
assertEquals(additionalProperties.getOrDefault(key, null), expected);
|
||||
private void want(ConfigAssert configAssert, String key, Object expected) {
|
||||
configAssert.assertValue(key, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -90,7 +91,7 @@ public class CodegenConfiguratorTest {
|
||||
CodegenConfig config = clientOptInput.getConfig();
|
||||
config.processOpts();
|
||||
|
||||
Map<String, Object> props = config.additionalProperties();
|
||||
ConfigAssert props = new ConfigAssert(config.additionalProperties());
|
||||
|
||||
// This verifies that things we expect to make it into the template will, as a result of this CodegenConfigurator.
|
||||
want(props, CodegenConstants.MODEL_PACKAGE, "model_package"); // * mutated by codegen
|
||||
@ -122,4 +123,4 @@ public class CodegenConfiguratorTest {
|
||||
want(props, "foo", "bar");
|
||||
want(props, "baz", "quux");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mockito;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.languages.AbstractJavaCodegen;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
@ -182,17 +183,13 @@ public class AbstractJavaCodegenTest {
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "invalidPackageName");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "invalidPackageName");
|
||||
Assert.assertEquals(codegen.apiPackage(), "invalidPackageName");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "invalidPackageName");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "get");
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), openAPI.getInfo().getVersion());
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.ARTIFACT_VERSION), openAPI.getInfo().getVersion());
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "invalidPackageName");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "invalidPackageName");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools");
|
||||
configAssert.assertValue(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "get");
|
||||
configAssert.assertValue(CodegenConstants.ARTIFACT_VERSION, codegen::getArtifactVersion, openAPI.getInfo().getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -209,18 +206,13 @@ public class AbstractJavaCodegenTest {
|
||||
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.zzzzzzz.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.zzzzzzz.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.zzzzzzz.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.zzzzzzz.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.zzzzzzz.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.zzzzzzz.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "is");
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "0.9.0-SNAPSHOT");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.ARTIFACT_VERSION), "0.9.0-SNAPSHOT");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.zzzzzzz.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.zzzzzzz.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.zzzzzzz.invoker");
|
||||
configAssert.assertValue(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "is");
|
||||
configAssert.assertValue(CodegenConstants.ARTIFACT_VERSION, codegen::getArtifactVersion, "0.9.0-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -234,18 +226,13 @@ public class AbstractJavaCodegenTest {
|
||||
|
||||
codegen.processOpts();
|
||||
codegen.preprocessOpenAPI(TestUtils.createOpenAPI());
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.model.oooooo");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.model.oooooo");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.api.oooooo");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.api.oooooo");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.invoker.oooooo");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.invoker.oooooo");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "getBoolean");
|
||||
Assert.assertEquals(codegen.getArtifactVersion(), "0.8.0-SNAPSHOT");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.ARTIFACT_VERSION), "0.8.0-SNAPSHOT");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.model.oooooo");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.api.oooooo");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.invoker.oooooo");
|
||||
configAssert.assertValue(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "getBoolean");
|
||||
configAssert.assertValue(CodegenConstants.ARTIFACT_VERSION, codegen::getArtifactVersion, "0.8.0-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -885,7 +872,7 @@ public class AbstractJavaCodegenTest {
|
||||
|
||||
@Test
|
||||
public void AnnotationsContainerTest() {
|
||||
codegen.additionalProperties().put("useBeanValidation", true);
|
||||
codegen.setUseBeanValidation(true);
|
||||
|
||||
// 1. string type
|
||||
Schema<?> schema = new ArraySchema().items(new Schema<>().type("string").pattern("^[a-z]$").minLength(0).maxLength(36));
|
||||
|
@ -32,6 +32,7 @@ import org.openapitools.codegen.languages.features.LoggingTestFeatures;
|
||||
import org.openapitools.codegen.languages.features.UseGenericResponseFeatures;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -89,15 +90,11 @@ public class JavaCXFClientCodegenTest {
|
||||
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -107,14 +104,11 @@ public class JavaCXFClientCodegenTest {
|
||||
codegen.setInvokerPackage("org.openapitools.client.xyz.invoker");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.client.xyz.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.client.xyz.invoker");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.client.xyz.invoker");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -124,14 +118,11 @@ public class JavaCXFClientCodegenTest {
|
||||
codegen.additionalProperties().put(CodegenConstants.INVOKER_PACKAGE,"org.openapitools.client.xyz.invoker");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.client.xyz.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.client.xyz.invoker");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.client.xyz.invoker");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -195,13 +186,14 @@ public class JavaCXFClientCodegenTest {
|
||||
JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
|
||||
|
||||
codegen.processOpts();
|
||||
Assert.assertNotNull(codegen.additionalProperties().get(AbstractJavaCodegen.OPENAPI_NULLABLE));
|
||||
Assert.assertTrue(codegen.isOpenApiNullable());
|
||||
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(AbstractJavaCodegen.OPENAPI_NULLABLE, codegen::isOpenApiNullable, Boolean.TRUE);
|
||||
|
||||
codegen.additionalProperties().put(AbstractJavaCodegen.OPENAPI_NULLABLE, false);
|
||||
codegen.processOpts();
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.OPENAPI_NULLABLE), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isOpenApiNullable());
|
||||
|
||||
configAssert.assertValue(AbstractJavaCodegen.OPENAPI_NULLABLE, codegen::isOpenApiNullable, Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -299,13 +291,13 @@ public class JavaCXFClientCodegenTest {
|
||||
JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
|
||||
|
||||
codegen.processOpts();
|
||||
Assert.assertNull(codegen.additionalProperties().get(AbstractJavaCodegen.JACKSON));
|
||||
Assert.assertFalse(codegen.isUseJackson());
|
||||
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(AbstractJavaCodegen.JACKSON, false);
|
||||
|
||||
codegen.additionalProperties().put(AbstractJavaCodegen.JACKSON, true);
|
||||
codegen.processOpts();
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.JACKSON), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isUseJackson());
|
||||
configAssert.assertValue(AbstractJavaCodegen.JACKSON, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -39,6 +39,7 @@ import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.openapitools.codegen.meta.features.SecurityFeature;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -216,23 +217,13 @@ public class JavaClientCodegenTest {
|
||||
public void testInitialConfigValues() throws Exception {
|
||||
final JavaClientCodegen codegen = new JavaClientCodegen();
|
||||
codegen.processOpts();
|
||||
|
||||
Assertions.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assertions.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
|
||||
Assertions.assertEquals(codegen.modelPackage(), "org.openapitools.client.model");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE),
|
||||
"org.openapitools.client.model");
|
||||
Assertions.assertEquals(codegen.apiPackage(), "org.openapitools.client.api");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.API_PACKAGE),
|
||||
"org.openapitools.client.api");
|
||||
Assertions.assertEquals(codegen.getInvokerPackage(), "org.openapitools.client");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE),
|
||||
"org.openapitools.client");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.client.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.client.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.client");
|
||||
Assertions.assertEquals(codegen.getSerializationLibrary(), JavaClientCodegen.SERIALIZATION_LIBRARY_GSON);
|
||||
configAssert.assertValue(JavaClientCodegen.SERIALIZATION_LIBRARY_GSON, "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -244,20 +235,12 @@ public class JavaClientCodegenTest {
|
||||
codegen.setInvokerPackage("xyz.yyyyy.zzzzzzz.invoker");
|
||||
codegen.setSerializationLibrary("JACKSON");
|
||||
codegen.processOpts();
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
|
||||
Assertions.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assertions.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assertions.assertEquals(codegen.modelPackage(), "xyz.yyyyy.zzzzzzz.model");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE),
|
||||
"xyz.yyyyy.zzzzzzz.model");
|
||||
Assertions.assertEquals(codegen.apiPackage(), "xyz.yyyyy.zzzzzzz.api");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.zzzzzzz.api");
|
||||
Assertions.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.zzzzzzz.invoker");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE),
|
||||
"xyz.yyyyy.zzzzzzz.invoker");
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.zzzzzzz.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.zzzzzzz.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.zzzzzzz.invoker");
|
||||
Assertions.assertEquals(codegen.getSerializationLibrary(), JavaClientCodegen.SERIALIZATION_LIBRARY_GSON); // the library JavaClientCodegen.OKHTTP_GSON only supports GSON
|
||||
}
|
||||
|
||||
@ -272,25 +255,16 @@ public class JavaClientCodegenTest {
|
||||
codegen
|
||||
.additionalProperties()
|
||||
.put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.iiii.invoker");
|
||||
codegen.additionalProperties().put(SERIALIZATION_LIBRARY, "JACKSON");
|
||||
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "JACKSON");
|
||||
codegen.additionalProperties().put(CodegenConstants.LIBRARY, JavaClientCodegen.JERSEY2);
|
||||
codegen.processOpts();
|
||||
|
||||
Assertions.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assertions.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assertions.assertEquals(codegen.modelPackage(), "xyz.yyyyy.zzzzzzz.mmmmm.model");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE),
|
||||
"xyz.yyyyy.zzzzzzz.mmmmm.model");
|
||||
Assertions.assertEquals(codegen.apiPackage(), "xyz.yyyyy.zzzzzzz.aaaaa.api");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.API_PACKAGE),
|
||||
"xyz.yyyyy.zzzzzzz.aaaaa.api");
|
||||
Assertions.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.zzzzzzz.iiii.invoker");
|
||||
Assertions.assertEquals(
|
||||
codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE),
|
||||
"xyz.yyyyy.zzzzzzz.iiii.invoker");
|
||||
Assertions.assertEquals(codegen.getSerializationLibrary(), SERIALIZATION_LIBRARY_JACKSON);
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, "xyz.yyyyy.zzzzzzz.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, "xyz.yyyyy.zzzzzzz.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.iiii.invoker");
|
||||
Assertions.assertEquals(codegen.getSerializationLibrary(), JavaClientCodegen.SERIALIZATION_LIBRARY_JACKSON);
|
||||
}
|
||||
|
||||
@Test public void testGeneratedAuthClassesJersey() {
|
||||
@ -344,14 +318,10 @@ public class JavaClientCodegenTest {
|
||||
|
||||
codegen.processOpts();
|
||||
|
||||
assertThat(codegen)
|
||||
.extracting(CodegenConfig::modelPackage, CodegenConfig::apiPackage, JavaClientCodegen::getInvokerPackage)
|
||||
.containsExactly("xyz.yyyyy.zzzzzzz.mmmmm.model", "xyz.yyyyy.zzzzzzz.aaaaa.api", "xyz.yyyyy.zzzzzzz.aaaaa");
|
||||
assertThat(codegen.additionalProperties()).contains(
|
||||
entry(CodegenConstants.MODEL_PACKAGE, "xyz.yyyyy.zzzzzzz.mmmmm.model"),
|
||||
entry(CodegenConstants.API_PACKAGE, "xyz.yyyyy.zzzzzzz.aaaaa.api"),
|
||||
entry(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.aaaaa")
|
||||
);
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.zzzzzzz.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.zzzzzzz.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.zzzzzzz.aaaaa");
|
||||
}
|
||||
|
||||
@Test public void testPackageNamesSetInvokerDerivedFromModel() {
|
||||
@ -360,14 +330,10 @@ public class JavaClientCodegenTest {
|
||||
|
||||
codegen.processOpts();
|
||||
|
||||
assertThat(codegen)
|
||||
.extracting(CodegenConfig::modelPackage, CodegenConfig::apiPackage, JavaClientCodegen::getInvokerPackage)
|
||||
.containsExactly("xyz.yyyyy.zzzzzzz.mmmmm.model", "org.openapitools.client.api", "xyz.yyyyy.zzzzzzz.mmmmm");
|
||||
assertThat(codegen.additionalProperties()).contains(
|
||||
entry(CodegenConstants.MODEL_PACKAGE, "xyz.yyyyy.zzzzzzz.mmmmm.model"),
|
||||
entry(CodegenConstants.API_PACKAGE, "org.openapitools.client.api"),
|
||||
entry(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.zzzzzzz.mmmmm")
|
||||
);
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.zzzzzzz.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.client.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.zzzzzzz.mmmmm");
|
||||
}
|
||||
|
||||
@Test public void testGetSchemaTypeWithComposedSchemaWithAllOf() {
|
||||
|
@ -25,6 +25,7 @@ import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.languages.AbstractJavaJAXRSServerCodegen;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
@ -65,15 +66,12 @@ public class AbstractJavaJAXRSServerCodegenTest {
|
||||
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8082");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(AbstractJavaJAXRSServerCodegen.SERVER_PORT, "8082");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -84,14 +82,11 @@ public class AbstractJavaJAXRSServerCodegenTest {
|
||||
codegen.setInvokerPackage("xx.yyyyyyyy.invoker");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xx.yyyyyyyy.invoker");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xx.yyyyyyyy.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xx.yyyyyyyy.invoker");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -106,16 +101,12 @@ public class AbstractJavaJAXRSServerCodegenTest {
|
||||
OpenAPI openAPI = new OpenAPI();
|
||||
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8088");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.iiii.invoker");
|
||||
configAssert.assertValue(AbstractJavaJAXRSServerCodegen.SERVER_PORT, "8088");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -12,6 +12,7 @@ import org.openapitools.codegen.languages.AbstractJavaCodegen;
|
||||
import org.openapitools.codegen.languages.AbstractJavaJAXRSServerCodegen;
|
||||
import org.openapitools.codegen.languages.JavaCXFExtServerCodegen;
|
||||
import org.openapitools.codegen.languages.features.*;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -84,10 +85,6 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
return useAnnotatedBasePath;
|
||||
}
|
||||
|
||||
// BeanValidationFeatures.USE_BEANVALIDATION
|
||||
public boolean isUseBeanValidation() {
|
||||
return useBeanValidation;
|
||||
}
|
||||
|
||||
// BeanValidationExtendedFeatures.USE_BEANVALIDATION_FEATURE
|
||||
public boolean isUseBeanValidationFeature() {
|
||||
@ -422,58 +419,50 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Map<String, Object> additionalProperties = codegen.additionalProperties();
|
||||
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
// Options processed by DefaultCodegen
|
||||
assertNull(additionalProperties.get(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS));
|
||||
assertEquals(additionalProperties.get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
// NOT WRITTEN BACK assertEquals(additionalProperties.get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
assertNull(additionalProperties.get(CodegenConstants.DOCEXTENSION));
|
||||
assertNull(additionalProperties.get(CodegenConstants.ENSURE_UNIQUE_PARAMS));
|
||||
assertEquals(additionalProperties.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
// NOT WRITTEN BACK assertEquals(additionalProperties.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, false);
|
||||
|
||||
assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
assertEquals(additionalProperties.get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.api");
|
||||
assertNull(additionalProperties.get(CodegenConstants.MODEL_NAME_PREFIX));
|
||||
assertNull(additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX));
|
||||
assertEquals(additionalProperties.get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
assertNull(additionalProperties.get(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS));
|
||||
assertNull(additionalProperties.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX));
|
||||
assertNull(additionalProperties.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG));
|
||||
assertNull(additionalProperties.get(CodegenConstants.TEMPLATE_DIR));
|
||||
// Options processed by AbstractJavaCodegen
|
||||
assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_DESCRIPTION), "OpenAPI Java");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_ID), "openapi-cxf-server");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_VERSION), "1.0.0");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_URL),
|
||||
"https://github.com/openapitools/openapi-generator");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_EMAIL), "team@openapitools.org");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_NAME), "OpenAPI-Generator Contributors");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION), "OpenAPITools.org");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION_URL), "http://openapitools.org");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.GROUP_ID), "org.openapitools");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.LICENSE_NAME), "Unlicense");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.LICENSE_URL), "http://unlicense.org");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.SCM_CONNECTION),
|
||||
"scm:git:git@github.com:openapitools/openapi-generator.git");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.SCM_DEVELOPER_CONNECTION),
|
||||
"scm:git:git@github.com:openapitools/openapi-generator.git");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.SCM_URL),
|
||||
"https://github.com/openapitools/openapi-generator");
|
||||
configAssert.assertValue(CodegenConstants.ARTIFACT_ID, "openapi-cxf-server");
|
||||
configAssert.assertValue(CodegenConstants.ARTIFACT_VERSION, "1.0.0");
|
||||
configAssert.assertValue(CodegenConstants.ARTIFACT_URL, "https://github.com/openapitools/openapi-generator");
|
||||
configAssert.assertValue(CodegenConstants.DEVELOPER_EMAIL, "team@openapitools.org");
|
||||
configAssert.assertValue(CodegenConstants.DEVELOPER_NAME, "OpenAPI-Generator Contributors");
|
||||
configAssert.assertValue(CodegenConstants.DEVELOPER_ORGANIZATION, "OpenAPITools.org");
|
||||
configAssert.assertValue(CodegenConstants.DEVELOPER_ORGANIZATION_URL, "http://openapitools.org");
|
||||
configAssert.assertValue(CodegenConstants.GROUP_ID, "org.openapitools");
|
||||
configAssert.assertValue(CodegenConstants.LICENSE_NAME, "Unlicense");
|
||||
configAssert.assertValue(CodegenConstants.LICENSE_URL, "http://unlicense.org");
|
||||
configAssert.assertValue(CodegenConstants.SCM_CONNECTION, "scm:git:git@github.com:openapitools/openapi-generator.git");
|
||||
configAssert.assertValue(CodegenConstants.SCM_DEVELOPER_CONNECTION, "scm:git:git@github.com:openapitools/openapi-generator.git");
|
||||
configAssert.assertValue(CodegenConstants.SCM_URL, "https://github.com/openapitools/openapi-generator");
|
||||
assertNull(additionalProperties.get(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING));
|
||||
assertEquals(additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL), Boolean.FALSE);
|
||||
assertEquals(additionalProperties.get(CodegenConstants.SOURCE_FOLDER), "src/gen/java");
|
||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "get");
|
||||
configAssert.assertValue(CodegenConstants.SERIALIZABLE_MODEL, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.SOURCE_FOLDER, "src/gen/java");
|
||||
configAssert.assertValue(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "get");
|
||||
assertNull(additionalProperties.get(AbstractJavaCodegen.DATE_LIBRARY));
|
||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.DISABLE_HTML_ESCAPING), Boolean.FALSE);
|
||||
configAssert.assertValue(AbstractJavaCodegen.DISABLE_HTML_ESCAPING, Boolean.FALSE);
|
||||
assertNull(additionalProperties.get(AbstractJavaCodegen.SUPPORT_ASYNC));
|
||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.WITH_XML), false);
|
||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.OPENAPI_NULLABLE), true);
|
||||
// Options processed by AbstractJavaJAXRSServerCodegen
|
||||
configAssert.assertValue(AbstractJavaCodegen.WITH_XML, false);
|
||||
configAssert.assertValue(AbstractJavaCodegen.OPENAPI_NULLABLE, true);
|
||||
assertNull(additionalProperties.get(CodegenConstants.IMPL_FOLDER));
|
||||
assertEquals(additionalProperties.get(BeanValidationFeatures.USE_BEANVALIDATION), Boolean.TRUE);
|
||||
assertEquals(additionalProperties.get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8082");
|
||||
// Options processed by JavaCXFServerCodegen
|
||||
configAssert.assertValue(BeanValidationFeatures.USE_BEANVALIDATION, Boolean.TRUE);
|
||||
configAssert.assertValue(AbstractJavaJAXRSServerCodegen.SERVER_PORT, "8082");
|
||||
assertNull(additionalProperties.get(BeanValidationExtendedFeatures.USE_BEANVALIDATION_FEATURE));
|
||||
assertNull(additionalProperties.get(GzipFeatures.USE_GZIP_FEATURE));
|
||||
assertNull(additionalProperties.get(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS));
|
||||
@ -509,14 +498,11 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
codegen.setInvokerPackage("xx.yyyyyyyy.invoker");
|
||||
codegen.processOpts();
|
||||
|
||||
Map<String, Object> additionalProperties = codegen.additionalProperties();
|
||||
assertEquals(additionalProperties.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyyyyy.model");
|
||||
assertEquals(codegen.apiPackage(), "xx.yyyyyyyy.api");
|
||||
assertEquals(additionalProperties.get(CodegenConstants.API_PACKAGE), "xx.yyyyyyyy.api");
|
||||
assertEquals(codegen.getInvokerPackage(), "xx.yyyyyyyy.invoker");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP,codegen::isHideGenerationTimestamp, false);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xx.yyyyyyyy.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xx.yyyyyyyy.invoker");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||
import org.openapitools.codegen.languages.AbstractJavaJAXRSServerCodegen;
|
||||
import org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
@ -55,17 +56,13 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaJAXRSSpecServerCodegen.SERVER_PORT), "8082");
|
||||
Assert.assertEquals(codegen.getOpenApiSpecFileLocation(), "src/main/openapi/openapi.yaml");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION), "src/main/openapi/openapi.yaml");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP,codegen::isHideGenerationTimestamp, false);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.api");
|
||||
codegen.additionalProperties().put(JavaJAXRSSpecServerCodegen.SERVER_PORT, "8082");
|
||||
codegen.additionalProperties().put(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "src/main/openapi/openapi.yaml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,16 +75,12 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
codegen.setOpenApiSpecFileLocation("src/main/resources/META-INF/openapi.yaml");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), true);
|
||||
Assert.assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.getOpenApiSpecFileLocation(), "src/main/resources/META-INF/openapi.yaml");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION), "src/main/resources/META-INF/openapi.yaml");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP,codegen::isHideGenerationTimestamp, true);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xx.yyyyyyyy.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xx.yyyyyyyy.invoker");
|
||||
configAssert.assertValue(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "src/main/resources/META-INF/openapi.yaml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -106,18 +99,14 @@ public class JavaJAXRSSpecServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), true);
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8088");
|
||||
Assert.assertEquals(codegen.getOpenApiSpecFileLocation(), "openapi.yml");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION), "openapi.yml");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SUPPORT_ASYNC), "true");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP,codegen::isHideGenerationTimestamp, true);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.iiii.invoker");
|
||||
configAssert.assertValue(AbstractJavaJAXRSServerCodegen.SERVER_PORT, "8088");
|
||||
configAssert.assertValue(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, codegen::getOpenApiSpecFileLocation, "openapi.yml");
|
||||
configAssert.assertValue(SUPPORT_ASYNC, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ import org.openapitools.codegen.languages.JavaJerseyServerCodegen;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.templating.MustacheEngineAdapter;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
@ -58,15 +59,12 @@ public class JavaJerseyServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaJerseyServerCodegen.SERVER_PORT), "8082");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, "org.openapitools.api");
|
||||
configAssert.assertValue(JavaJerseyServerCodegen.SERVER_PORT, "8082");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,14 +76,12 @@ public class JavaJerseyServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
codegen.setDateLibrary("java8");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), true);
|
||||
Assert.assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xx.yyyyyyyy.invoker");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, true);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, "xx.yyyyyyyy.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.getDateLibrary(), "java8");
|
||||
}
|
||||
|
||||
@ -102,14 +98,11 @@ public class JavaJerseyServerCodegenTest extends JavaJaxrsBaseTest {
|
||||
openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), true);
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, true);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaJerseyServerCodegen.SERVER_PORT), "8088");
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||
import org.openapitools.codegen.languages.JavaMicronautClientCodegen;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -40,15 +41,11 @@ public class JavaMicronautClientCodegenTest extends AbstractMicronautCodegenTest
|
||||
openAPI.addServersItem(new Server().url("https://one.com/v2"));
|
||||
openAPI.setInfo(new Info());
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -10,6 +10,7 @@ import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||
import org.openapitools.codegen.languages.JavaMicronautServerCodegen;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -43,16 +44,12 @@ public class JavaMicronautServerCodegenTest extends AbstractMicronautCodegenTest
|
||||
openAPI.addServersItem(new Server().url("https://one.com/v2"));
|
||||
openAPI.setInfo(new Info());
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.controller");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.controller");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaMicronautServerCodegen.OPT_CONTROLLER_PACKAGE), "org.openapitools.controller");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.controller");
|
||||
configAssert.assertValue(JavaMicronautServerCodegen.OPT_CONTROLLER_PACKAGE, "org.openapitools.controller");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -26,6 +26,7 @@ import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.languages.JavaPlayFrameworkCodegen;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -39,18 +40,13 @@ public class JavaPlayFrameworkCodegenTest {
|
||||
final JavaPlayFrameworkCodegen codegen = new JavaPlayFrameworkCodegen();
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
Assert.assertEquals(codegen.modelPackage(), "apimodels");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "apimodels");
|
||||
Assert.assertEquals(codegen.apiPackage(), "controllers");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "controllers");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getBasePackage(), "org.openapitools");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaPlayFrameworkCodegen.BASE_PACKAGE), "org.openapitools");
|
||||
Assert.assertEquals(codegen.getConfigPackage(), "org.openapitools.configuration");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaPlayFrameworkCodegen.CONFIG_PACKAGE), "org.openapitools.configuration");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, false);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "apimodels");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "controllers");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.api");
|
||||
configAssert.assertValue(JavaPlayFrameworkCodegen.BASE_PACKAGE, codegen::getBasePackage, "org.openapitools");
|
||||
configAssert.assertValue(JavaPlayFrameworkCodegen.CONFIG_PACKAGE, codegen::getConfigPackage, "org.openapitools.configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -63,19 +59,13 @@ public class JavaPlayFrameworkCodegenTest {
|
||||
codegen.setBasePackage("xx.yyyyyyyy.base");
|
||||
codegen.setConfigPackage("xx.yyyyyyyy.config");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), true);
|
||||
Assert.assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.getBasePackage(), "xx.yyyyyyyy.base");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaPlayFrameworkCodegen.BASE_PACKAGE), "xx.yyyyyyyy.base");
|
||||
Assert.assertEquals(codegen.getConfigPackage(), "xx.yyyyyyyy.config");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaPlayFrameworkCodegen.CONFIG_PACKAGE), "xx.yyyyyyyy.config");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xx.yyyyyyyy.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xx.yyyyyyyy.invoker");
|
||||
configAssert.assertValue(JavaPlayFrameworkCodegen.BASE_PACKAGE, codegen::getBasePackage, "xx.yyyyyyyy.base");
|
||||
configAssert.assertValue(JavaPlayFrameworkCodegen.CONFIG_PACKAGE, "xx.yyyyyyyy.config");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -89,19 +79,13 @@ public class JavaPlayFrameworkCodegenTest {
|
||||
codegen.additionalProperties().put(JavaPlayFrameworkCodegen.CONFIG_PACKAGE,"xyz.yyyyy.cccc.config");
|
||||
codegen.additionalProperties().put("serverPort","8088");
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertEquals(codegen.isHideGenerationTimestamp(), true);
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.getBasePackage(), "xyz.yyyyy.bbbb.base");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaPlayFrameworkCodegen.BASE_PACKAGE), "xyz.yyyyy.bbbb.base");
|
||||
Assert.assertEquals(codegen.getConfigPackage(), "xyz.yyyyy.cccc.config");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(JavaPlayFrameworkCodegen.CONFIG_PACKAGE), "xyz.yyyyy.cccc.config");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.iiii.invoker");
|
||||
configAssert.assertValue(JavaPlayFrameworkCodegen.BASE_PACKAGE, codegen::getBasePackage, "xyz.yyyyy.bbbb.base");
|
||||
configAssert.assertValue(JavaPlayFrameworkCodegen.CONFIG_PACKAGE, codegen::getConfigPackage, "xyz.yyyyy.cccc.config");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,6 +37,7 @@ import org.openapitools.codegen.languages.SpringCodegen;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures;
|
||||
import org.openapitools.codegen.testutils.ConfigAssert;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Ignore;
|
||||
@ -551,20 +552,15 @@ public class SpringCodegenTest {
|
||||
openAPI.getInfo().setTitle("Some test API");
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker");
|
||||
Assert.assertEquals(codegen.getBasePackage(), "xyz.yyyyy.bbbb.base");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "xyz.yyyyy.bbbb.base");
|
||||
Assert.assertEquals(codegen.getConfigPackage(), "xyz.yyyyy.cccc.config");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "xyz.yyyyy.cccc.config");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.TITLE), "someTest");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8088");
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xyz.yyyyy.mmmmm.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xyz.yyyyy.aaaaa.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xyz.yyyyy.iiii.invoker");
|
||||
configAssert.assertValue(SpringCodegen.BASE_PACKAGE, "xyz.yyyyy.bbbb.base");
|
||||
configAssert.assertValue(SpringCodegen.CONFIG_PACKAGE, "xyz.yyyyy.cccc.config");
|
||||
configAssert.assertValue(SpringCodegen.TITLE, "someTest");
|
||||
configAssert.assertValue(SpringCodegen.SERVER_PORT, "8088");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -651,21 +647,31 @@ public class SpringCodegenTest {
|
||||
openAPI.setInfo(new Info());
|
||||
codegen.preprocessOpenAPI(openAPI);
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
Assert.assertFalse(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
Assert.assertEquals(codegen.getBasePackage(), "org.openapitools");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "org.openapitools");
|
||||
Assert.assertEquals(codegen.getConfigPackage(), "org.openapitools.configuration");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "org.openapitools.configuration");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8082");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING), false);
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.USE_RESPONSE_ENTITY), true);
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||
// Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
// configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.FALSE);
|
||||
// Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "org.openapitools.model");
|
||||
// Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "org.openapitools.api");
|
||||
// Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "org.openapitools.api");
|
||||
// Assert.assertEquals(codegen.getBasePackage(), "org.openapitools");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "org.openapitools");
|
||||
configAssert.assertValue(SpringCodegen.BASE_PACKAGE, "org.openapitools");
|
||||
// Assert.assertEquals(codegen.getConfigPackage(), "org.openapitools.configuration");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "org.openapitools.configuration");
|
||||
configAssert.assertValue(SpringCodegen.CONFIG_PACKAGE, "org.openapitools.configuration");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8082");
|
||||
configAssert.assertValue(SpringCodegen.SERVER_PORT, "8082");
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING), false);
|
||||
configAssert.assertValue(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING, false);
|
||||
configAssert.assertValue(SpringCodegen.USE_RESPONSE_ENTITY, true);
|
||||
// Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.USE_RESPONSE_ENTITY), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1151,20 +1157,14 @@ public class SpringCodegenTest {
|
||||
codegen.setUnhandledException(true);
|
||||
codegen.processOpts();
|
||||
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||
Assert.assertTrue(codegen.isHideGenerationTimestamp());
|
||||
Assert.assertEquals(codegen.modelPackage(), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyyyyy.model");
|
||||
Assert.assertEquals(codegen.apiPackage(), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xx.yyyyyyyy.api");
|
||||
Assert.assertEquals(codegen.getInvokerPackage(), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xx.yyyyyyyy.invoker");
|
||||
Assert.assertEquals(codegen.getBasePackage(), "xx.yyyyyyyy.base");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "xx.yyyyyyyy.base");
|
||||
Assert.assertEquals(codegen.getConfigPackage(), "xx.yyyyyyyy.config");
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "xx.yyyyyyyy.config");
|
||||
Assert.assertTrue(codegen.isUnhandledException());
|
||||
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING), true);
|
||||
ConfigAssert configAssert = new ConfigAssert(codegen.additionalProperties());
|
||||
configAssert.assertValue(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codegen::isHideGenerationTimestamp, Boolean.TRUE);
|
||||
configAssert.assertValue(CodegenConstants.MODEL_PACKAGE, codegen::modelPackage, "xx.yyyyyyyy.model");
|
||||
configAssert.assertValue(CodegenConstants.API_PACKAGE, codegen::apiPackage, "xx.yyyyyyyy.api");
|
||||
configAssert.assertValue(CodegenConstants.INVOKER_PACKAGE, codegen::getInvokerPackage, "xx.yyyyyyyy.invoker");
|
||||
configAssert.assertValue(SpringCodegen.BASE_PACKAGE, codegen::getBasePackage, "xx.yyyyyyyy.base");
|
||||
configAssert.assertValue(SpringCodegen.CONFIG_PACKAGE, codegen::getConfigPackage, "xx.yyyyyyyy.config");
|
||||
configAssert.assertValue(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING, codegen::isUnhandledException, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1658,7 +1658,7 @@ public class SpringCodegenTest {
|
||||
input.config(codegen);
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
codegen.setHateoas(true);
|
||||
// codegen.setHateoas(true);
|
||||
generator.setGenerateMetadata(false); // skip metadata and ↓ only generate models
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
|
||||
|
@ -0,0 +1,63 @@
|
||||
package org.openapitools.codegen.testutils;
|
||||
|
||||
import com.samskivert.mustache.MustacheEvaluator;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Utility class to assert variable values in mustache.
|
||||
*
|
||||
* @See {@link org.openapitools.codegen.DefaultCodegen#useCodegenAsMustacheParentContext() useCodegenAsMustacheParentContext}
|
||||
*
|
||||
* The values come from additionalProperties or from codegen if useCodegenAsMustacheParentContext is called
|
||||
*/
|
||||
public class ConfigAssert {
|
||||
|
||||
private final MustacheEvaluator evaluator;
|
||||
|
||||
public ConfigAssert(Map<String, Object> additionalProperties) {
|
||||
this.evaluator = MustacheEvaluator.create(additionalProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate a mustache variable.
|
||||
*
|
||||
* @param name mustache variable
|
||||
* @return the value as seen by mustache as {{{name}}}
|
||||
*/
|
||||
public Object getValue(String name) {
|
||||
return evaluator.getValue(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that property is correctly initialized for mustache.
|
||||
*
|
||||
* @param name mustache variable
|
||||
* @param expectedValue value to match.
|
||||
*
|
||||
* @throws AssertionError in case of mismatch
|
||||
*/
|
||||
public void assertValue(String name, Object expectedValue) {
|
||||
Object actual = getValue(name);
|
||||
Assertions.assertEquals(expectedValue, actual, name + "not matching in mustache context");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that property is correctly initialized for mustache and in java.
|
||||
*
|
||||
* @param name mustache variable
|
||||
* @param getter value provider in java code (typically in DefaultCodegen or children of DefaultCodegen)
|
||||
* @param expectedValue value to match.
|
||||
*
|
||||
* @throws AssertionError in case of mismatch
|
||||
*/
|
||||
public void assertValue(String name, Supplier<Object> getter, Object expectedValue) {
|
||||
Object actual = getValue(name);
|
||||
Object codeGenExpectedValue = getter.get();
|
||||
Assertions.assertEquals(codeGenExpectedValue, actual, "valueNotFound in codegen");
|
||||
Assertions.assertEquals(expectedValue, actual, name + "not matching in mustache context");
|
||||
}
|
||||
}
|
@ -1,26 +1,53 @@
|
||||
# OpenAPI generated API stub
|
||||
# spring-cloud-oas3
|
||||
|
||||
Spring Framework stub
|
||||
## Requirements
|
||||
|
||||
Building the API client library requires [Maven](https://maven.apache.org/) to be installed.
|
||||
|
||||
## Overview
|
||||
This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub.
|
||||
This is an example of building API stub interfaces in Java using the Spring framework.
|
||||
## Installation
|
||||
|
||||
The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints
|
||||
by adding ```@Controller``` classes that implement the interface. Eg:
|
||||
```java
|
||||
@Controller
|
||||
public class PetController implements PetApi {
|
||||
// implement all PetApi methods
|
||||
}
|
||||
To install the API client library to your local Maven repository, simply execute:
|
||||
|
||||
```shell
|
||||
mvn install
|
||||
```
|
||||
|
||||
You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg:
|
||||
```java
|
||||
@FeignClient(name="pet", url="http://petstore.swagger.io/v2")
|
||||
public interface PetClient extends PetApi {
|
||||
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
|
||||
|
||||
}
|
||||
```shell
|
||||
mvn deploy
|
||||
```
|
||||
|
||||
Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.
|
||||
|
||||
### Maven users
|
||||
|
||||
Add this dependency to your project's POM:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>org.openapitools.openapi3</groupId>
|
||||
<artifactId>spring-cloud-oas3</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle users
|
||||
|
||||
Add this dependency to your project's build file:
|
||||
|
||||
```groovy
|
||||
compile "org.openapitools.openapi3:spring-cloud-oas3:1.0.0"
|
||||
```
|
||||
|
||||
### Others
|
||||
|
||||
At first generate the JAR by executing:
|
||||
|
||||
mvn package
|
||||
|
||||
Then manually install the following JARs:
|
||||
|
||||
* target/spring-cloud-oas3-1.0.0.jar
|
||||
* target/lib/*.jar
|
||||
|
Loading…
x
Reference in New Issue
Block a user