Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to ignore import mappings in model generation. #9981

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public class Generate implements Runnable {
@Option(name = {"--skip-alias-generation"}, title = "skip alias generation.", description = "skip code generation for models identified as alias.")
private Boolean skipAliasGeneration;

@Option(name = {"--ignore-import-mapping"}, title = "ignore import mapping", description = "allow generate model classes using names previously listed on import mappings.")
private String ignoreImportMappings;

@Override
public void run() {

Expand Down Expand Up @@ -280,6 +283,10 @@ public void run() {
configurator.setSkipAliasGeneration(removeOperationIdPrefix);
}

if (ignoreImportMappings != null) {
additionalProperties.add(String.format("%s=%s", CodegenConstants.IGNORE_IMPORT_MAPPING_OPTION, Boolean.parseBoolean(ignoreImportMappings)));
}

applySystemPropertiesKvpList(systemProperties, configurator);
applyInstantiationTypesKvpList(instantiationTypes, configurator);
applyImportMappingsKvpList(importMappings, configurator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,10 @@ public interface CodegenConfig {

Boolean getSkipAliasGeneration();

boolean getIgnoreImportMapping();

void setIgnoreImportMapping(boolean ignoreImportMapping);

boolean defaultIgnoreImportMappingOption();

}
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,6 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String ASP_NET_CORE_VERSION = "aspnetCoreVersion";
public static final String INTERFACE_ONLY = "interface-only";
public static final String INTERFACE_CONTROLLER = "interface-controller";

public static final String IGNORE_IMPORT_MAPPING_OPTION = "ignoreImportMappings";
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class DefaultCodegen {
protected String httpUserAgent;
protected Boolean hideGenerationTimestamp = true;
protected Boolean skipAliasGeneration;
protected boolean ignoreImportMapping;
// How to encode special characters like $
// They are translated to words like "Dollar" and prefixed with '
// Then translated back during JSON encoding and decoding
Expand Down Expand Up @@ -163,6 +164,12 @@ public void processOpts() {
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
}

if (additionalProperties.get(CodegenConstants.IGNORE_IMPORT_MAPPING_OPTION) != null) {
setIgnoreImportMapping(Boolean.parseBoolean( additionalProperties.get(CodegenConstants.IGNORE_IMPORT_MAPPING_OPTION).toString()));
} else {
setIgnoreImportMapping(defaultIgnoreImportMappingOption());
}
}

// override with any special post-processing for all models
Expand Down Expand Up @@ -3958,4 +3965,16 @@ protected void configureDataForTestTemplate(CodegenOperation codegenOperation) {
}
codegenOperation.testPath = path;
}

public boolean getIgnoreImportMapping() {
return ignoreImportMapping;
}

public void setIgnoreImportMapping(boolean ignoreImportMapping) {
this.ignoreImportMapping = ignoreImportMapping;
}

public boolean defaultIgnoreImportMappingOption() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private Model getParent(Model model) {
for (String name : modelKeys) {
try {
//don't generate models that have an import mapping
if (config.importMapping().containsKey(name)) {
if (!config.getIgnoreImportMapping() && config.importMapping().containsKey(name)) {
LOGGER.info("Model " + name + " not imported due to import mapping");
continue;
}
Expand Down Expand Up @@ -409,7 +409,7 @@ private Model getParent(Model model) {
models.put("modelPackage", config.modelPackage());
try {
//don't generate models that have an import mapping
if (config.importMapping().containsKey(modelName)) {
if (!config.getIgnoreImportMapping() && config.importMapping().containsKey(modelName)) {
continue;
}
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public String toParamName(String name) {
public String toModelName(final String name) {
// We need to check if import-mapping has a different model for this class, so we use it
// instead of the auto-generated one.
if (importMapping.containsKey(name)) {
if (!getIgnoreImportMapping() && importMapping.containsKey(name)) {
return importMapping.get(name);
}

Expand Down Expand Up @@ -1349,4 +1349,8 @@ public String sanitizeTag(String tag) {
return tag;
}

public boolean defaultIgnoreImportMappingOption() {
return true;
}

}