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

allow skip model alias for generators. #9959

Merged
merged 1 commit into from
Jan 5, 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 @@ -172,6 +172,9 @@ public class Generate implements Runnable {
description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
private Boolean removeOperationIdPrefix;

@Option(name = {"--skip-alias-generation"}, title = "skip alias generation.", description = "skip code generation for models identified as alias.")
private Boolean skipAliasGeneration;

@Override
public void run() {

Expand Down Expand Up @@ -273,6 +276,10 @@ public void run() {
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
}

if (skipAliasGeneration != null) {
configurator.setSkipAliasGeneration(removeOperationIdPrefix);
}

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

String sanitizeName(String name);

void setSkipAliasGeneration(Boolean skipAliasGeneration);

Boolean getSkipAliasGeneration();

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class DefaultCodegen {
protected String gitUserId, gitRepoId, releaseNote;
protected String httpUserAgent;
protected Boolean hideGenerationTimestamp = true;
protected Boolean skipAliasGeneration;
// 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 @@ -3449,6 +3450,14 @@ public void setSkipOverwrite(boolean skipOverwrite) {
this.skipOverwrite = skipOverwrite;
}

public void setSkipAliasGeneration(Boolean skipAliasGeneration) {
this.skipAliasGeneration = skipAliasGeneration;
}

public Boolean getSkipAliasGeneration() {
return this.skipAliasGeneration;
}

public boolean isRemoveOperationIdPrefix() {
return removeOperationIdPrefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ private Model getParent(Model model) {
// post process all processed models
allProcessedModels = config.postProcessAllModels(allProcessedModels);

final boolean skipAlias = config.getSkipAliasGeneration() != null && config.getSkipAliasGeneration();

// generate files based on processed models
for (String modelName : allProcessedModels.keySet()) {
Map<String, Object> models = (Map<String, Object>) allProcessedModels.get(modelName);
Expand All @@ -411,7 +413,7 @@ private Model getParent(Model model) {
continue;
}
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
if (config instanceof AbstractJavaCodegen) {
if (skipAlias) {
// Special handling of aliases only applies to Java
if (modelTemplate != null && modelTemplate.containsKey("model")) {
CodegenModel m = (CodegenModel) modelTemplate.get("model");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class CodegenConfigurator implements Serializable {
private String outputDir;
private boolean verbose;
private boolean skipOverwrite;
private Boolean skipAliasGeneration;
private boolean removeOperationIdPrefix;
private String templateDir;
private String auth;
Expand Down Expand Up @@ -126,6 +127,10 @@ public CodegenConfigurator setRemoveOperationIdPrefix(boolean removeOperationIdP
return this;
}

public void setSkipAliasGeneration(Boolean skipAliasGeneration) {
this.skipAliasGeneration = skipAliasGeneration;
}

public String getModelNameSuffix() {
return modelNameSuffix;
}
Expand Down Expand Up @@ -392,6 +397,7 @@ public ClientOptInput toClientOptInput() {
config.setInputSpec(inputSpec);
config.setOutputDir(outputDir);
config.setSkipOverwrite(skipOverwrite);
config.setSkipAliasGeneration(skipAliasGeneration);
config.setIgnoreFilePathOverride(ignoreFileOverride);
config.setRemoveOperationIdPrefix(removeOperationIdPrefix);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ public void processOpts() {
} else if (dateLibrary.equals("legacy")) {
additionalProperties.put("legacyDates", true);
}

if (this.skipAliasGeneration == null) {
this.skipAliasGeneration = Boolean.TRUE;
}
}

private void sanitizeConfig() {
Expand Down