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

Typescript Angular 2: Make service suffix configurable #341

Merged
merged 5 commits into from
Jun 25, 2018
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 @@ -43,11 +43,14 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
public static final String TAGGED_UNIONS = "taggedUnions";
public static final String NG_VERSION = "ngVersion";
public static final String PROVIDED_IN_ROOT ="providedInRoot";

public static final String SERVICE_SUFFIX = "serviceSuffix";
public static final String SERVICE_FILE_SUFFIX = "serviceFileSuffix";

protected String npmName = null;
protected String npmVersion = "1.0.0";
protected String npmRepository = null;
protected String serviceSuffix = "Service";
protected String serviceFileSuffix = ".service";

private boolean taggedUnions = false;

Expand Down Expand Up @@ -81,6 +84,8 @@ public TypeScriptAngularClientCodegen() {
"Use this property to provide Injectables in root (it is only valid in angular version greater or equal to 6.0.0).",
SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular. Default is '4.3'"));
this.cliOptions.add(new CliOption(SERVICE_SUFFIX, "The suffix of the generated service. Default is 'Service'."));
this.cliOptions.add(new CliOption(SERVICE_FILE_SUFFIX, "The suffix of the file of the generated service (service<suffix>.ts). Default is '.service'."));
}

@Override
Expand Down Expand Up @@ -159,6 +164,12 @@ public void processOpts() {
if (!ngVersion.atLeast("4.3.0")) {
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
}
if (additionalProperties.containsKey(SERVICE_SUFFIX)) {
serviceSuffix = additionalProperties.get(SERVICE_SUFFIX).toString();
}
if (additionalProperties.containsKey(SERVICE_FILE_SUFFIX)) {
serviceFileSuffix = additionalProperties.get(SERVICE_FILE_SUFFIX).toString();
}
}

private void addNpmPackageGeneration(SemVer ngVersion) {
Expand Down Expand Up @@ -418,15 +429,15 @@ public String toApiName(String name) {
if (name.length() == 0) {
return "DefaultService";
}
return initialCaps(name) + "Service";
return initialCaps(name) + serviceSuffix;
}

@Override
public String toApiFilename(String name) {
if (name.length() == 0) {
return "default.service";
}
return camelize(name, true) + ".service";
return camelize(name, true) + serviceFileSuffix;
}

@Override
Expand Down Expand Up @@ -469,7 +480,7 @@ public void setNpmRepository(String npmRepository) {
}

private String getApiFilenameFromClassname(String classname) {
String name = classname.substring(0, classname.length() - "Service".length());
String name = classname.substring(0, classname.length() - serviceSuffix.length());
return toApiFilename(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class TypeScriptAngularClientOptionsProvider implements OptionsProvider {
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
public static final String NG_VERSION = "2";
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
public static String SERVICE_SUFFIX = "Service";
public static String SERVICE_FILE_SUFFIX = ".service";

@Override
public String getLanguage() {
Expand All @@ -56,6 +58,8 @@ public Map<String, String> createOptions() {
.put(TypeScriptAngularClientCodegen.TAGGED_UNIONS, Boolean.FALSE.toString())
.put(TypeScriptAngularClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
.put(TypeScriptAngularClientCodegen.NG_VERSION, NG_VERSION)
.put(TypeScriptAngularClientCodegen.SERVICE_SUFFIX, SERVICE_SUFFIX)
.put(TypeScriptAngularClientCodegen.SERVICE_FILE_SUFFIX, SERVICE_FILE_SUFFIX)
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.2-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.2-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.2-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.2-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.2-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.2-SNAPSHOT