Skip to content

Commit 9555a1d

Browse files
authored
Merge pull request #8183 from topce/provided-in-root
[typescript-angular] add providedIn support
2 parents 3ecf62a + e611ae3 commit 9555a1d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
3030
public static final String WITH_INTERFACES = "withInterfaces";
3131
public static final String TAGGED_UNIONS ="taggedUnions";
3232
public static final String NG_VERSION = "ngVersion";
33+
public static final String PROVIDED_IN_ROOT ="providedInRoot";
3334

3435
protected String npmName = null;
3536
protected String npmVersion = "1.0.0";
@@ -63,6 +64,9 @@ public TypeScriptAngularClientCodegen() {
6364
this.cliOptions.add(new CliOption(TAGGED_UNIONS,
6465
"Use discriminators to create tagged unions instead of extending interfaces.",
6566
BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
67+
this.cliOptions.add(new CliOption(PROVIDED_IN_ROOT,
68+
"Use this property to provide Injectables in root (it is only valid in angular version greater or equal to 6.0.0).",
69+
BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
6670
this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular. Default is '4.3'"));
6771
}
6872

@@ -123,6 +127,10 @@ public void processOpts() {
123127
taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString());
124128
}
125129

130+
if (additionalProperties.containsKey(PROVIDED_IN_ROOT) && !ngVersion.atLeast("6.0.0")) {
131+
additionalProperties.put(PROVIDED_IN_ROOT,false);
132+
}
133+
126134
additionalProperties.put(NG_VERSION, ngVersion);
127135
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
128136
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));

modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ import { {{classname}}Interface } from './{{classFile
4141
* {{&description}}
4242
*/
4343
{{/description}}
44+
{{^providedInRoot}}
4445
@Injectable()
46+
{{/providedInRoot}}
47+
{{#providedInRoot}}
48+
@Injectable({
49+
providedIn: 'root'
50+
})
51+
{{/providedInRoot}}
4552
{{#withInterfaces}}
4653
export class {{classname}} implements {{classname}}Interface {
4754
{{/withInterfaces}}

modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngularClientOptionsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public Map<String, String> createOptions() {
3535
.put(TypeScriptAngularClientCodegen.NPM_VERSION, NMP_VERSION)
3636
.put(TypeScriptAngularClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
3737
.put(TypeScriptAngularClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString())
38+
.put(TypeScriptAngularClientCodegen.PROVIDED_IN_ROOT, Boolean.FALSE.toString())
3839
.put(TypeScriptAngularClientCodegen.TAGGED_UNIONS, Boolean.FALSE.toString())
3940
.put(TypeScriptAngularClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
4041
.put(TypeScriptAngularClientCodegen.NG_VERSION, NG_VERSION)

0 commit comments

Comments
 (0)