mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-08 16:40:56 +00:00
Typescript Angular 2: Make service suffix configurable (#341)
* Added serviceSuffix and serviceFileSuffix parameters to control the suffixes of generated class and file names * Updated TypeScriptAngularClientOptionsProvider to include the new serviceSuffix and serviceFileSuffix parameters * Fixed part in generator where hardcoded 'Service' suffix was used. * Made the . in the service file name part of the config setting * Updated cli message
This commit is contained in:
parent
a0bfe2bf72
commit
38bb732673
@ -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;
|
||||
|
||||
@ -81,6 +84,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
"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
|
||||
@ -159,6 +164,12 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
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) {
|
||||
@ -418,7 +429,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
if (name.length() == 0) {
|
||||
return "DefaultService";
|
||||
}
|
||||
return initialCaps(name) + "Service";
|
||||
return initialCaps(name) + serviceSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -426,7 +437,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
if (name.length() == 0) {
|
||||
return "default.service";
|
||||
}
|
||||
return camelize(name, true) + ".service";
|
||||
return camelize(name, true) + serviceFileSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -469,7 +480,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
@ -56,6 +58,8 @@ public class TypeScriptAngularClientOptionsProvider implements OptionsProvider {
|
||||
.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();
|
||||
|
@ -1 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
3.0.2-SNAPSHOT
|
@ -1 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
3.0.2-SNAPSHOT
|
@ -1 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
3.0.2-SNAPSHOT
|
@ -1 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
3.0.2-SNAPSHOT
|
@ -1 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
3.0.2-SNAPSHOT
|
@ -1 +1 @@
|
||||
3.0.1-SNAPSHOT
|
||||
3.0.2-SNAPSHOT
|
Loading…
x
Reference in New Issue
Block a user