[typescript-angular] add provided in support (#120)

* add provided in root support

* fix unit test to pass test generation of new options

* set default for providedInRoot to be true
This commit is contained in:
topce
2018-05-24 18:20:16 +02:00
committed by William Cheng
parent 22e94fb4d8
commit 4bc5ffe867
83 changed files with 3876 additions and 371 deletions

View File

@@ -42,6 +42,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
public static final String WITH_INTERFACES = "withInterfaces";
public static final String TAGGED_UNIONS = "taggedUnions";
public static final String NG_VERSION = "ngVersion";
public static final String PROVIDED_IN_ROOT ="providedInRoot";
protected String npmName = null;
protected String npmVersion = "1.0.0";
@@ -75,6 +77,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
this.cliOptions.add(new CliOption(TAGGED_UNIONS,
"Use discriminators to create tagged unions instead of extending interfaces.",
SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(PROVIDED_IN_ROOT,
"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'"));
}
@@ -135,6 +140,17 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString());
}
if (ngVersion.atLeast("6.0.0")) {
if (!additionalProperties.containsKey(PROVIDED_IN_ROOT)){
additionalProperties.put(PROVIDED_IN_ROOT,true);
}else {
additionalProperties.put(PROVIDED_IN_ROOT,Boolean.valueOf(
(String) additionalProperties.get(PROVIDED_IN_ROOT)));
}
}else {
additionalProperties.put(PROVIDED_IN_ROOT,false);
}
additionalProperties.put(NG_VERSION, ngVersion);
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));