Skip to content

Commit c0e872f

Browse files
authored
Merge pull request #11106 from swagger-api/typescript-angular-sample
added samples for typescript angular versions 7 to 11
2 parents ac5d379 + ab51f3a commit c0e872f

File tree

375 files changed

+59139
-0
lines changed

Some content is hidden

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

375 files changed

+59139
-0
lines changed
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 -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v10 --additional-properties ngVersion=10.0.0"
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 -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v11 --additional-properties ngVersion=11.0.0"
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 -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v7 --additional-properties ngVersion=7.0.0"
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 -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v8 --additional-properties ngVersion=8.0.0"
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 -Dlogback.configurationFile=bin/logback.xml"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v9 --additional-properties ngVersion=9.0.0"
30+
31+
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
wwwroot/*.js
2+
node
3+
node_modules
4+
typings
5+
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+
3.0.28-SNAPSHOT
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
## @swagger/angular2-typescript-petstore@0.0.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 dist``` (don't forget to specify the `dist` folder!)
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 @swagger/[email protected] --save
23+
```
24+
25+
_without publishing (not recommended):_
26+
27+
```
28+
npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save
29+
```
30+
31+
It's important to take the tgz file, otherwise you'll get trouble with links on windows.
32+
33+
_using `npm link`:_
34+
35+
In PATH_TO_GENERATED_PACKAGE/dist:
36+
```
37+
npm link
38+
```
39+
40+
In your project:
41+
```
42+
npm link @swagger/angular2-typescript-petstore
43+
```
44+
45+
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
46+
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
47+
Published packages are not effected by this issue.
48+
49+
50+
#### General usage
51+
52+
In your Angular project:
53+
54+
55+
```
56+
// without configuring providers
57+
import { ApiModule } from '@swagger/angular2-typescript-petstore';
58+
import { HttpClientModule } from '@angular/common/http';
59+
60+
61+
@NgModule({
62+
imports: [
63+
ApiModule,
64+
// make sure to import the HttpClientModule in the AppModule only,
65+
// see https://github.com/angular/angular/issues/20575
66+
HttpClientModule
67+
],
68+
declarations: [ AppComponent ],
69+
providers: [],
70+
bootstrap: [ AppComponent ]
71+
})
72+
export class AppModule {}
73+
```
74+
75+
```
76+
// configuring providers
77+
import { ApiModule, Configuration, ConfigurationParameters } from '@swagger/angular2-typescript-petstore';
78+
79+
export function apiConfigFactory (): Configuration => {
80+
const params: ConfigurationParameters = {
81+
// set configuration parameters here.
82+
}
83+
return new Configuration(params);
84+
}
85+
86+
@NgModule({
87+
imports: [ ApiModule.forRoot(apiConfigFactory) ],
88+
declarations: [ AppComponent ],
89+
providers: [],
90+
bootstrap: [ AppComponent ]
91+
})
92+
export class AppModule {}
93+
```
94+
95+
```
96+
import { DefaultApi } from '@swagger/angular2-typescript-petstore';
97+
98+
export class AppComponent {
99+
constructor(private apiGateway: DefaultApi) { }
100+
}
101+
```
102+
103+
Note: The ApiModule is restricted to being instantiated once app wide.
104+
This is to ensure that all services are treated as singletons.
105+
106+
#### Using multiple swagger files / APIs / ApiModules
107+
In order to use multiple `ApiModules` generated from different swagger files,
108+
you can create an alias name when importing the modules
109+
in order to avoid naming conflicts:
110+
```
111+
import { ApiModule } from 'my-api-path';
112+
import { ApiModule as OtherApiModule } from 'my-other-api-path';
113+
import { HttpClientModule } from '@angular/common/http';
114+
115+
116+
@NgModule({
117+
imports: [
118+
ApiModule,
119+
OtherApiModule,
120+
// make sure to import the HttpClientModule in the AppModule only,
121+
// see https://github.com/angular/angular/issues/20575
122+
HttpClientModule
123+
]
124+
})
125+
export class AppModule {
126+
127+
}
128+
```
129+
130+
131+
### Set service base path
132+
If different than the generated base path, during app bootstrap, you can provide the base path to your service.
133+
134+
```
135+
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
136+
137+
bootstrap(AppComponent, [
138+
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
139+
]);
140+
```
141+
or
142+
143+
```
144+
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
145+
146+
@NgModule({
147+
imports: [],
148+
declarations: [ AppComponent ],
149+
providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ],
150+
bootstrap: [ AppComponent ]
151+
})
152+
export class AppModule {}
153+
```
154+
155+
156+
#### Using @angular/cli
157+
First extend your `src/environments/*.ts` files by adding the corresponding base path:
158+
159+
```
160+
export const environment = {
161+
production: false,
162+
API_BASE_PATH: 'http://127.0.0.1:8080'
163+
};
164+
```
165+
166+
In the src/app/app.module.ts:
167+
```
168+
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
169+
import { environment } from '../environments/environment';
170+
171+
@NgModule({
172+
declarations: [
173+
AppComponent
174+
],
175+
imports: [ ],
176+
providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
177+
bootstrap: [ AppComponent ]
178+
})
179+
export class AppModule { }
180+
```

0 commit comments

Comments
 (0)