Skip to content

Commit a004b19

Browse files
akehirwing328
authored andcommitted
[typescript-angular] Added support for Angular v6 (by adding support for RxJS v6) (#8155)
* Change RxJS imports, if using Angular >= 6 * Add testcases for Angular v5 and v6 * Remove unwanted whitespace in padding, and restore petstore with interfaces * Update according to review of @macjohnny * Correct padding for typescript v2 test, and revert typescript with interfaces readme
1 parent 9020d88 commit a004b19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+23446
-26
lines changed

bin/typescript-angular-petstore-all.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ java $JAVA_OPTS -jar $executable $ags
5757

5858
echo "Typescript Petstore API client (v5 { Uses latest version of ng-packagr })"
5959
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v5/npm --additional-properties ngVersion=5"
60-
java $JAVA_OPTS -jar $executable $ags
60+
java $JAVA_OPTS -jar $executable $ags
61+
62+
echo "Typescript Petstore API client (v6 { Uses RxJS version 6 })"
63+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v6/npm --additional-properties ngVersion=6"
64+
java $JAVA_OPTS -jar $executable $ags
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v6/npm --additional-properties ngVersion=6"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/windows/typescript-angular-petstore-all.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ call .\bin\windows\typescript-angular-v2.bat
66
call .\bin\windows\typescript-angular-v4-with-npm.bat
77
call .\bin\windows\typescript-angular-v4.3-with-npm.bat
88
call .\bin\windows\typescript-angular-v5-with-npm.bat
9-
9+
call .\bin\windows\typescript-angular-v6-with-npm.bat
1010

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8+
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -c bin\typescript-petstore-npm.json -l typescript-angular -o samples\client\petstore\typescript-angular-v6\npm --additional-properties ngVersion=6
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public void processOpts() {
127127
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
128128
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
129129
additionalProperties.put("useHttpClient", ngVersion.atLeast("4.3.0"));
130+
additionalProperties.put("useRxJS6", ngVersion.atLeast("6.0.0"));
130131
if (!ngVersion.atLeast("4.3.0")) {
131132
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
132133
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import { Response, ResponseContentType } from '@angular/http
1414
import { CustomQueryEncoderHelper } from '../encoder';
1515
{{/useHttpClient}}
1616

17+
{{^useRxJS6}}
1718
import { Observable } from 'rxjs/Observable';
19+
{{/useRxJS6}}
20+
{{#useRxJS6}}
21+
import { Observable } from 'rxjs';
22+
{{/useRxJS6}}
1823
{{^useHttpClient}}
1924
import '../rxjs-operators';
2025
{{/useHttpClient}}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { HttpHeaders } from '@angular/comm
66
import { Headers } from '@angular/http';
77
{{/useHttpClient}}
88

9+
{{^useRxJS6}}
910
import { Observable } from 'rxjs/Observable';
10-
11+
{{/useRxJS6}}
12+
{{#useRxJS6}}
13+
import { Observable } from 'rxjs';
14+
{{/useRxJS6}}
1115

1216
{{#imports}}
1317
import { {{classname}} } from '../{{filename}}';

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@angular/compiler": "^{{ngVersion}}",
2929
"core-js": "^2.4.0",
3030
"reflect-metadata": "^0.1.3",
31-
"rxjs": "^5.4.0",
31+
"rxjs": "{{#useRxJS6}}^6.1.0{{/useRxJS6}}{{^useRxJS6}}^5.4.0{{/useRxJS6}}",
3232
"zone.js": "^0.7.6"
3333
},
3434
"devDependencies": {
@@ -40,9 +40,9 @@
4040
"@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}}
4141
"ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}"^2.4.1"{{/useOldNgPackagr}},{{/useNgPackagr}}
4242
"reflect-metadata": "^0.1.3",
43-
"rxjs": "^5.4.0",
43+
"rxjs": "{{#useRxJS6}}^6.1.0{{/useRxJS6}}{{^useRxJS6}}^5.4.0{{/useRxJS6}}",
4444
"zone.js": "^0.7.6",
45-
"typescript": "^2.1.5"
45+
"typescript": ">=2.1.5 <2.8"
4646
}{{#npmRepository}},{{/npmRepository}}
4747
{{#npmRepository}}
4848
"publishConfig": {

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@
859859
<!--<module>samples/client/petstore/typescript-angular-v2/npm</module>-->
860860
<module>samples/client/petstore/typescript-angular-v4/npm</module>
861861
<module>samples/client/petstore/typescript-angular-v4.3/npm</module>
862+
<module>samples/client/petstore/typescript-angular-v5/npm</module>
863+
<module>samples/client/petstore/typescript-angular-v6/npm</module>
862864
<!--<module>samples/client/petstore/bash</module>-->
863865
</modules>
864866
</profile>

samples/client/petstore/typescript-angular-v2/npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"reflect-metadata": "^0.1.3",
3535
"rxjs": "^5.4.0",
3636
"zone.js": "^0.7.6",
37-
"typescript": "^2.1.5"
37+
"typescript": ">=2.1.5 <2.8"
3838
},
3939
"publishConfig": {
4040
"registry": "https://skimdb.npmjs.com/registry"

0 commit comments

Comments
 (0)