Skip to content

[JavaScript] Add model name prefix/suffix to JavaScript client #2300

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

Merged
merged 1 commit into from
Mar 4, 2016
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 @@ -754,7 +754,7 @@ public Map<String, Object> processModels(CodegenConfig config, Map<String, Model
CodegenModel cm = config.fromModel(key, mm, allDefinitions);
Map<String, Object> mo = new HashMap<String, Object>();
mo.put("model", cm);
mo.put("importPath", config.toModelImport(key));
mo.put("importPath", config.toModelImport(cm.classname));
models.add(mo);

allImports.addAll(cm.imports);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void processOpts() {
typeMapping.put("number", "Number");
typeMapping.put("DateTime", "Date");
typeMapping.put("Date", "Date");
typeMapping.put("file", "File");
// binary not supported in JavaScript client right now, using String as a workaround
typeMapping.put("binary", "String");

Expand Down Expand Up @@ -293,6 +294,14 @@ public String toParamName(String name) {
public String toModelName(String name) {
name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"

if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}

if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}

// camelize the model name
// phone_number => PhoneNumber
name = camelize(name);
Expand All @@ -315,7 +324,7 @@ public String toModelFilename(String name) {

@Override
public String toModelImport(String name) {
return toModelName(name);
return name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public String toOperationId(String operationId) {

@Override
public String toModelImport(String name) {
return gemName + "/" + modelPackage() + "/" + toModelFilename(name);
return gemName + "/" + modelPackage() + "/" + underscore(name);
}

@Override
Expand Down