Skip to content

Commit d37f809

Browse files
feikedewing328
authored andcommitted
typescript-angular: Ng43 with interfaces petstore scripts (#8102)
* Added petstore sample scripts and output for ng 4.3 withInterfaces generation * Added petstore sample scripts and output for ng v5 withInterfaces generation
1 parent 6bd95e7 commit d37f809

Some content is hidden

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

54 files changed

+4072
-0
lines changed

bin/typescript-angular-petstore-all.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ echo "Typescript Petstore API client (with interfaces generated)"
3939
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -o samples/client/petstore/typescript-angular-v2/with-interfaces -D withInterfaces=true --additional-properties ngVersion=2"
4040
java $JAVA_OPTS -jar $executable $ags
4141

42+
echo "Typescript Petstore API client (with interfaces generated and v4.3 HttpClientModule)"
43+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -o samples/client/petstore/typescript-angular-v4.3/with-interfaces -D withInterfaces=true --additional-properties ngVersion=4.3"
44+
java $JAVA_OPTS -jar $executable $ags
45+
46+
echo "Typescript Petstore API client (with interfaces generated and v5 HttpClientModule)"
47+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -o samples/client/petstore/typescript-angular-v5/with-interfaces -D withInterfaces=true --additional-properties ngVersion=5"
48+
java $JAVA_OPTS -jar $executable $ags
49+
4250
echo "Typescript Petstore API client (v4 { Adding InjectionToken Over OpaqueToken })"
4351
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-v4/npm --additional-properties ngVersion=4"
4452
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 -o samples/client/petstore/typescript-angular-v4.3/with-interfaces -D withInterfaces=true --additional-properties ngVersion=4.3"
30+
31+
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 -o samples/client/petstore/typescript-angular-v5/with-interfaces -D withInterfaces=true --additional-properties ngVersion=5"
30+
31+
java $JAVA_OPTS -jar $executable $ags

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
call .\bin\windows\typescript-angular-v2-with-npm.bat
22
call .\bin\windows\typescript-angular-v2-interfaces.bat
3+
call .\bin\windows\typescript-angular-v4.3-interfaces.bat
4+
call .\bin\windows\typescript-angular-v5-interfaces.bat
35
call .\bin\windows\typescript-angular-v2.bat
46
call .\bin\windows\typescript-angular-v4-with-npm.bat
57
call .\bin\windows\typescript-angular-v4.3-with-npm.bat
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-v4.3\with-interfaces -D withInterfaces=true --additional-properties ngVersion=4.3
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%
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-v5\with-interfaces -D withInterfaces=true --additional-properties ngVersion=5
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swagger Codegen Ignore
2+
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.4.0-SNAPSHOT
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
## @
2+
3+
### Building
4+
5+
To install the required dependencies and to build the typescript sources run:
6+
```
7+
npm install
8+
npm run build
9+
```
10+
11+
### publishing
12+
13+
First build the package than run ```npm publish```
14+
15+
### consuming
16+
17+
Navigate to the folder of your consuming project and run one of next commands.
18+
19+
_published:_
20+
21+
```
22+
npm install @ --save
23+
```
24+
25+
_without publishing (not recommended):_
26+
27+
```
28+
npm install PATH_TO_GENERATED_PACKAGE --save
29+
```
30+
31+
_using `npm link`:_
32+
33+
In PATH_TO_GENERATED_PACKAGE:
34+
```
35+
npm link
36+
```
37+
38+
In your project:
39+
```
40+
npm link
41+
```
42+
43+
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
44+
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
45+
Published packages are not effected by this issue.
46+
47+
48+
#### General usage
49+
50+
In your Angular project:
51+
52+
53+
```
54+
// without configuring providers
55+
import { ApiModule } from '';
56+
import { HttpClientModule } from '@angular/common/http';
57+
58+
59+
@NgModule({
60+
imports: [
61+
ApiModule,
62+
// make sure to import the HttpClientModule in the AppModule only,
63+
// see https://github.com/angular/angular/issues/20575
64+
HttpClientModule
65+
],
66+
declarations: [ AppComponent ],
67+
providers: [],
68+
bootstrap: [ AppComponent ]
69+
})
70+
export class AppModule {}
71+
```
72+
73+
```
74+
// configuring providers
75+
import { ApiModule, Configuration, ConfigurationParameters } from '';
76+
77+
export function apiConfigFactory (): Configuration => {
78+
const params: ConfigurationParameters = {
79+
// set configuration parameters here.
80+
}
81+
return new Configuration(params);
82+
}
83+
84+
@NgModule({
85+
imports: [ ApiModule.forRoot(apiConfigFactory) ],
86+
declarations: [ AppComponent ],
87+
providers: [],
88+
bootstrap: [ AppComponent ]
89+
})
90+
export class AppModule {}
91+
```
92+
93+
```
94+
import { DefaultApi } from '';
95+
96+
export class AppComponent {
97+
constructor(private apiGateway: DefaultApi) { }
98+
}
99+
```
100+
101+
Note: The ApiModule is restricted to being instantiated once app wide.
102+
This is to ensure that all services are treated as singletons.
103+
104+
#### Using multiple swagger files / APIs / ApiModules
105+
In order to use multiple `ApiModules` generated from different swagger files,
106+
you can create an alias name when importing the modules
107+
in order to avoid naming conflicts:
108+
```
109+
import { ApiModule } from 'my-api-path';
110+
import { ApiModule as OtherApiModule } from 'my-other-api-path';
111+
import { HttpClientModule } from '@angular/common/http';
112+
113+
114+
@NgModule({
115+
imports: [
116+
ApiModule,
117+
OtherApiModule,
118+
// make sure to import the HttpClientModule in the AppModule only,
119+
// see https://github.com/angular/angular/issues/20575
120+
HttpClientModule
121+
]
122+
})
123+
export class AppModule {
124+
125+
}
126+
```
127+
128+
129+
### Set service base path
130+
If different than the generated base path, during app bootstrap, you can provide the base path to your service.
131+
132+
```
133+
import { BASE_PATH } from '';
134+
135+
bootstrap(AppComponent, [
136+
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
137+
]);
138+
```
139+
or
140+
141+
```
142+
import { BASE_PATH } from '';
143+
144+
@NgModule({
145+
imports: [],
146+
declarations: [ AppComponent ],
147+
providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ],
148+
bootstrap: [ AppComponent ]
149+
})
150+
export class AppModule {}
151+
```
152+
153+
154+
#### Using @angular/cli
155+
First extend your `src/environments/*.ts` files by adding the corresponding base path:
156+
157+
```
158+
export const environment = {
159+
production: false,
160+
API_BASE_PATH: 'http://127.0.0.1:8080'
161+
};
162+
```
163+
164+
In the src/app/app.module.ts:
165+
```
166+
import { BASE_PATH } from '';
167+
import { environment } from '../environments/environment';
168+
169+
@NgModule({
170+
declarations: [
171+
AppComponent
172+
],
173+
imports: [ ],
174+
providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
175+
bootstrap: [ AppComponent ]
176+
})
177+
export class AppModule { }
178+
```

0 commit comments

Comments
 (0)