Skip to content

[TS][Angular2] Updated npm configuration to use new typescript2 typings system #5965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,37 @@ _unPublished (not recommended):_
npm install PATH_TO_GENERATED_PACKAGE --save
```

_using `npm link`:_

In PATH_TO_GENERATED_PACKAGE:
```
npm link
```

In your project:
```
npm link {{npmName}}@{{npmVersion}}
```

In your angular2 project:

TODO: paste example.
```
import { DefaultApi } from '{{npmName}}/api/api';
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: [AppModule]
})
export class CoreModule {}
```
```
import { DefaultApi } from '{{npmName}}/api/api';

export class AppComponent {
constructor(private apiGateway: DefaultApi) { }
}
```

### Set service base path
If different than the generated base path, during app bootstrap, you can provide the base path to your service.
Expand All @@ -41,4 +69,30 @@ import { BASE_PATH } from './path-to-swagger-gen-service/index';
bootstrap(AppComponent, [
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
]);
```

#### Using @angular/cli
First extend your `src/environments/*.ts` files by adding the corresponding base path:

```
export const environment = {
production: false,
API_BASE_PATH: 'http://127.0.0.1:8080'
};
```

In the src/app/app.module.ts:
```
import { BASE_PATH } from '{{npmName}}';
import { environment } from '../environments/environment';

@NgModule({
declarations: [
AppComponent,
],
imports: [ ],
providers: [{ provide: BASE_PATH, useValue: useValue: environment.API_BASE_PATH }],
bootstrap: [AppComponent]
})
export class AppModule { }
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,29 @@
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "typings install && tsc --outDir dist/",
"build": "tsc",
"postinstall": "npm run build"
},
"peerDependencies": {
"@angular/core": "^2.0.0-rc.5",
"@angular/http": "^2.0.0-rc.5",
"@angular/common": "^2.0.0-rc.5",
"@angular/compiler": "^2.0.0-rc.5",
"@angular/core": "^2.2.2",
"@angular/http": "^2.2.2",
"@angular/common": "^2.2.2",
"@angular/compiler": "^2.2.2",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.17"
"rxjs": "^5.1.0",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/core": "^2.0.0-rc.5",
"@angular/http": "^2.0.0-rc.5",
"@angular/common": "^2.0.0-rc.5",
"@angular/compiler": "^2.0.0-rc.5",
"@angular/platform-browser": "^2.0.0-rc.5",
"core-js": "^2.4.0",
"@angular/core": "^2.2.2",
"@angular/http": "^2.2.2",
"@angular/common": "^2.2.2",
"@angular/compiler": "^2.2.2",
"@angular/platform-browser": "^2.2.2",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.17",
"typescript": "^1.8.10",
"typings": "^1.3.2"
"rxjs": "5.1.0",
"zone.js": "^0.7.6",
"typescript": "^2.1.5"
}{{#npmRepository}},{{/npmRepository}}
{{#npmRepository}}
"publishConfig":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"module": "commonjs",
"module": "es6",
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"outDir": "./dist",
"noLib": false,
"declaration": true
"declaration": true,
"lib": [ "es6", "dom" ]
},
"exclude": [
"node_modules",
"typings/main.d.ts",
"typings/main",
"dist"
],
"filesGlob": [
"./model/*.ts",
"./api/*.ts",
"typings/browser.d.ts"
"./api/*.ts"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ export class PetApi {
}
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/json',
'application/xml'
];

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -253,7 +253,7 @@ export class PetApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -304,7 +304,7 @@ export class PetApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -355,7 +355,7 @@ export class PetApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -403,7 +403,7 @@ export class PetApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -442,13 +442,13 @@ export class PetApi {
}
// to determine the Content-Type header
let consumes: string[] = [
'application/json',
'application/json',
'application/xml'
];

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -504,7 +504,7 @@ export class PetApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class StoreApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -202,7 +202,7 @@ export class StoreApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -240,7 +240,7 @@ export class StoreApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -232,7 +232,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -273,7 +273,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -315,7 +315,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -354,7 +354,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -405,7 +405,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -438,7 +438,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down Expand Up @@ -482,7 +482,7 @@ export class UserApi {

// to determine the Accept header
let produces: string[] = [
'application/xml',
'application/xml',
'application/json'
];

Expand Down
56 changes: 55 additions & 1 deletion samples/client/petstore/typescript-angular2/npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,37 @@ _unPublished (not recommended):_
npm install PATH_TO_GENERATED_PACKAGE --save
```

_using `npm link`:_

In PATH_TO_GENERATED_PACKAGE:
```
npm link
```

In your project:
```
npm link @swagger/angular2-typescript-petstore@0.0.1
```

In your angular2 project:

TODO: paste example.
```
import { DefaultApi } from '@swagger/angular2-typescript-petstore/api/api';
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: [AppModule]
})
export class CoreModule {}
```
```
import { DefaultApi } from '@swagger/angular2-typescript-petstore/api/api';

export class AppComponent {
constructor(private apiGateway: DefaultApi) { }
}
```

### Set service base path
If different than the generated base path, during app bootstrap, you can provide the base path to your service.
Expand All @@ -41,4 +69,30 @@ import { BASE_PATH } from './path-to-swagger-gen-service/index';
bootstrap(AppComponent, [
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
]);
```

#### Using @angular/cli
First extend your `src/environments/*.ts` files by adding the corresponding base path:

```
export const environment = {
production: false,
API_BASE_PATH: 'http://127.0.0.1:8080'
};
```

In the src/app/app.module.ts:
```
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
import { environment } from '../environments/environment';

@NgModule({
declarations: [
AppComponent,
],
imports: [ ],
providers: [{ provide: BASE_PATH, useValue: useValue: environment.API_BASE_PATH }],
bootstrap: [AppComponent]
})
export class AppModule { }
```
Loading