diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache index 218831c42d1..5c46e73275f 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache @@ -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. @@ -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 { } ``` \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache index 8818224401a..b9d16d974eb 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache @@ -10,30 +10,29 @@ "main": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "build": "typings install && tsc --outDir dist/" + "build": "tsc --outDir dist/", + "postinstall": "npm run build" }, "peerDependencies": { - "@angular/core": "^2.0.0", - "@angular/http": "^2.0.0", - "@angular/common": "^2.0.0", - "@angular/compiler": "^2.0.0", + "@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.12", - "zone.js": "^0.6.17" + "rxjs": "^5.1.0", + "zone.js": "^0.7.6" }, "devDependencies": { - "@angular/core": "^2.0.0", - "@angular/http": "^2.0.0", - "@angular/common": "^2.0.0", - "@angular/compiler": "^2.0.0", - "@angular/platform-browser": "^2.0.0", - "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.12", - "zone.js": "^0.6.17", - "typescript": "^2.0.0", - "typings": "^1.3.2" + "rxjs": "5.1.0", + "zone.js": "^0.7.6", + "typescript": "^2.1.5" }{{#npmRepository}},{{/npmRepository}} {{#npmRepository}} "publishConfig":{ diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.mustache index 3db6e8690e9..a6e9096bbf7 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.mustache @@ -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" ] } diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/petstore-expected/api/user.service.ts b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/petstore-expected/api/user.service.ts index 2246435f5a0..8c92494c894 100644 --- a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/petstore-expected/api/user.service.ts +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/petstore-expected/api/user.service.ts @@ -221,7 +221,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -267,7 +267,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -313,7 +313,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -359,7 +359,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -403,7 +403,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -458,7 +458,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -497,7 +497,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; @@ -546,7 +546,7 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/xml', + 'application/xml', 'application/json' ]; diff --git a/samples/client/petstore/typescript-angular2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular2/default/api/pet.service.ts index e8f290f135d..0303ca70d3a 100644 --- a/samples/client/petstore/typescript-angular2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/pet.service.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -20,6 +20,7 @@ import { Response, ResponseContentType } from '@angular/http import { Observable } from 'rxjs/Observable'; import '../rxjs-operators'; +import { ApiResponse } from '../model/apiResponse'; import { Pet } from '../model/pet'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; @@ -77,7 +78,7 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public addPet(body?: Pet, extraHttpRequestParams?: any): Observable<{}> { + public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { return this.addPetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -110,7 +111,7 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatus(status?: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -126,7 +127,7 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTags(tags?: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -139,8 +140,8 @@ export class PetService { /** * Find pet by ID - * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * @param petId ID of pet that needs to be fetched + * Returns a single pet + * @param petId ID of pet to return */ public getPetById(petId: number, extraHttpRequestParams?: any): Observable { return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) @@ -158,7 +159,7 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePet(body?: Pet, extraHttpRequestParams?: any): Observable<{}> { + public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { return this.updatePetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -176,7 +177,7 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm(petId: string, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -194,7 +195,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable<{}> { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -211,17 +212,21 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body?: Pet, extraHttpRequestParams?: any): Observable { + public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling addPet.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (petstore_auth) required @@ -275,8 +280,8 @@ export class PetService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (petstore_auth) required @@ -308,23 +313,25 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatusWithHttpInfo(status?: Array, extraHttpRequestParams?: any): Observable { + public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByStatus'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'status' is not null or undefined + if (status === null || status === undefined) { + throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); + } if (status) { - status.forEach((element) => { - queryParameters.append('status', element); - }) + queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (petstore_auth) required @@ -356,23 +363,25 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTagsWithHttpInfo(tags?: Array, extraHttpRequestParams?: any): Observable { + public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/findByTags'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'tags' is not null or undefined + if (tags === null || tags === undefined) { + throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); + } if (tags) { - tags.forEach((element) => { - queryParameters.append('tags', element); - }) + queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (petstore_auth) required @@ -401,8 +410,8 @@ export class PetService { /** * Find pet by ID - * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * @param petId ID of pet that needs to be fetched + * Returns a single pet + * @param petId ID of pet to return */ public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/${petId}' @@ -418,8 +427,8 @@ export class PetService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (api_key) required @@ -427,15 +436,6 @@ export class PetService { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -456,17 +456,21 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body?: Pet, extraHttpRequestParams?: any): Observable { + public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling updatePet.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (petstore_auth) required @@ -503,7 +507,7 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithFormWithHttpInfo(petId: string, name?: string, status?: string, extraHttpRequestParams?: any): Observable { + public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/pet/${petId}' .replace('${' + 'petId' + '}', String(petId)); @@ -526,8 +530,8 @@ export class PetService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; // authentication (petstore_auth) required @@ -594,8 +598,7 @@ export class PetService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/json' ]; // authentication (petstore_auth) required diff --git a/samples/client/petstore/typescript-angular2/default/api/store.service.ts b/samples/client/petstore/typescript-angular2/default/api/store.service.ts index 937130527af..877c8df7e08 100644 --- a/samples/client/petstore/typescript-angular2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/store.service.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -108,7 +108,7 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderById(orderId: string, extraHttpRequestParams?: any): Observable { + public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -124,7 +124,7 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrder(body?: Order, extraHttpRequestParams?: any): Observable { + public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -155,8 +155,8 @@ export class StoreService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -187,8 +187,7 @@ export class StoreService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/json' ]; // authentication (api_key) required @@ -216,7 +215,7 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderByIdWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { + public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order/${orderId}' .replace('${' + 'orderId' + '}', String(orderId)); @@ -230,8 +229,8 @@ export class StoreService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -254,17 +253,21 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body?: Order, extraHttpRequestParams?: any): Observable { + public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/store/order'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling placeOrder.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; diff --git a/samples/client/petstore/typescript-angular2/default/api/user.service.ts b/samples/client/petstore/typescript-angular2/default/api/user.service.ts index a9d12993aff..5a5761dcdd3 100644 --- a/samples/client/petstore/typescript-angular2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/user.service.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -77,7 +77,7 @@ export class UserService { * This can only be done by the logged in user. * @param body Created user object */ - public createUser(body?: User, extraHttpRequestParams?: any): Observable<{}> { + public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { return this.createUserWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -93,7 +93,7 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInput(body?: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -109,7 +109,7 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInput(body?: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -158,7 +158,7 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser(username?: string, password?: string, extraHttpRequestParams?: any): Observable { + public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -190,7 +190,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser(username: string, body?: User, extraHttpRequestParams?: any): Observable<{}> { + public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -207,17 +207,21 @@ export class UserService { * This can only be done by the logged in user. * @param body Created user object */ - public createUserWithHttpInfo(body?: User, extraHttpRequestParams?: any): Observable { + public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUser.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -243,17 +247,21 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInputWithHttpInfo(body?: Array, extraHttpRequestParams?: any): Observable { + public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithArray'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -279,17 +287,21 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInputWithHttpInfo(body?: Array, extraHttpRequestParams?: any): Observable { + public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/createWithList'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -329,8 +341,8 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -367,8 +379,8 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -392,12 +404,20 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUserWithHttpInfo(username?: string, password?: string, extraHttpRequestParams?: any): Observable { + public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/login'; let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling loginUser.'); + } + // verify required parameter 'password' is not null or undefined + if (password === null || password === undefined) { + throw new Error('Required parameter password was null or undefined when calling loginUser.'); + } if (username !== undefined) { queryParameters.set('username', username); } @@ -409,8 +429,8 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -441,8 +461,8 @@ export class UserService { // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; @@ -466,7 +486,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUserWithHttpInfo(username: string, body?: User, extraHttpRequestParams?: any): Observable { + public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { const path = this.basePath + '/user/${username}' .replace('${' + 'username' + '}', String(username)); @@ -477,11 +497,15 @@ export class UserService { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling updateUser.'); + } // to determine the Accept header let produces: string[] = [ - 'application/json', - 'application/xml' + 'application/xml', + 'application/json' ]; diff --git a/samples/client/petstore/typescript-angular2/default/model/category.ts b/samples/client/petstore/typescript-angular2/default/model/category.ts index 202faef0d43..d09f8d7b265 100644 --- a/samples/client/petstore/typescript-angular2/default/model/category.ts +++ b/samples/client/petstore/typescript-angular2/default/model/category.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -12,6 +12,9 @@ +/** + * A category for a pet + */ export interface Category { id?: number; diff --git a/samples/client/petstore/typescript-angular2/default/model/models.ts b/samples/client/petstore/typescript-angular2/default/model/models.ts index 1f152369d80..8607c5dabd0 100644 --- a/samples/client/petstore/typescript-angular2/default/model/models.ts +++ b/samples/client/petstore/typescript-angular2/default/model/models.ts @@ -1,3 +1,4 @@ +export * from './apiResponse'; export * from './category'; export * from './order'; export * from './pet'; diff --git a/samples/client/petstore/typescript-angular2/default/model/order.ts b/samples/client/petstore/typescript-angular2/default/model/order.ts index 7e2cb037074..402a86689c8 100644 --- a/samples/client/petstore/typescript-angular2/default/model/order.ts +++ b/samples/client/petstore/typescript-angular2/default/model/order.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -12,6 +12,9 @@ +/** + * An order for a pets from the pet store + */ export interface Order { id?: number; diff --git a/samples/client/petstore/typescript-angular2/default/model/pet.ts b/samples/client/petstore/typescript-angular2/default/model/pet.ts index 7a429abf483..0d6137d02cf 100644 --- a/samples/client/petstore/typescript-angular2/default/model/pet.ts +++ b/samples/client/petstore/typescript-angular2/default/model/pet.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -14,6 +14,9 @@ import { Category } from './category'; import { Tag } from './tag'; +/** + * A pet for sale in the pet store + */ export interface Pet { id?: number; diff --git a/samples/client/petstore/typescript-angular2/default/model/tag.ts b/samples/client/petstore/typescript-angular2/default/model/tag.ts index 56cbe04b7a3..3ed1eeff8f3 100644 --- a/samples/client/petstore/typescript-angular2/default/model/tag.ts +++ b/samples/client/petstore/typescript-angular2/default/model/tag.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -12,6 +12,9 @@ +/** + * A tag for a pet + */ export interface Tag { id?: number; diff --git a/samples/client/petstore/typescript-angular2/default/model/user.ts b/samples/client/petstore/typescript-angular2/default/model/user.ts index 202adb58c73..f4914ae2608 100644 --- a/samples/client/petstore/typescript-angular2/default/model/user.ts +++ b/samples/client/petstore/typescript-angular2/default/model/user.ts @@ -1,9 +1,9 @@ /** * Swagger Petstore - * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * Contact: apiteam@wordnik.com + * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git @@ -12,6 +12,9 @@ +/** + * A User who is purchasing from the pet store + */ export interface User { id?: number; diff --git a/samples/client/petstore/typescript-angular2/default/variables.ts b/samples/client/petstore/typescript-angular2/default/variables.ts index 7ef7e51c24f..6fe58549f39 100644 --- a/samples/client/petstore/typescript-angular2/default/variables.ts +++ b/samples/client/petstore/typescript-angular2/default/variables.ts @@ -6,4 +6,4 @@ export const COLLECTION_FORMATS = { 'tsv': ' ', 'ssv': ' ', 'pipes': '|' -} \ No newline at end of file +} diff --git a/samples/client/petstore/typescript-angular2/npm/README.md b/samples/client/petstore/typescript-angular2/npm/README.md index fbf37be47b0..038fd51491c 100644 --- a/samples/client/petstore/typescript-angular2/npm/README.md +++ b/samples/client/petstore/typescript-angular2/npm/README.md @@ -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. @@ -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 { } ``` \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/npm/package.json b/samples/client/petstore/typescript-angular2/npm/package.json index cca1493f9d9..e266f06e353 100644 --- a/samples/client/petstore/typescript-angular2/npm/package.json +++ b/samples/client/petstore/typescript-angular2/npm/package.json @@ -10,30 +10,29 @@ "main": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "build": "typings install && tsc --outDir dist/" + "build": "tsc --outDir dist/", + "postinstall": "npm run build" }, "peerDependencies": { - "@angular/core": "^2.0.0", - "@angular/http": "^2.0.0", - "@angular/common": "^2.0.0", - "@angular/compiler": "^2.0.0", + "@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.12", - "zone.js": "^0.6.17" + "rxjs": "^5.1.0", + "zone.js": "^0.7.6" }, "devDependencies": { - "@angular/core": "^2.0.0", - "@angular/http": "^2.0.0", - "@angular/common": "^2.0.0", - "@angular/compiler": "^2.0.0", - "@angular/platform-browser": "^2.0.0", - "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.12", - "zone.js": "^0.6.17", - "typescript": "^2.0.0", - "typings": "^1.3.2" + "rxjs": "5.1.0", + "zone.js": "^0.7.6", + "typescript": "^2.1.5" }, "publishConfig":{ "registry":"https://skimdb.npmjs.com/registry" diff --git a/samples/client/petstore/typescript-angular2/npm/tsconfig.json b/samples/client/petstore/typescript-angular2/npm/tsconfig.json index 3db6e8690e9..a6e9096bbf7 100644 --- a/samples/client/petstore/typescript-angular2/npm/tsconfig.json +++ b/samples/client/petstore/typescript-angular2/npm/tsconfig.json @@ -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" ] } diff --git a/samples/client/petstore/typescript-angular2/npm/variables.ts b/samples/client/petstore/typescript-angular2/npm/variables.ts index d06561e7dac..6fe58549f39 100644 --- a/samples/client/petstore/typescript-angular2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular2/npm/variables.ts @@ -1,4 +1,4 @@ -import { InjectionToken } from '@angular/core'; +import { InjectionToken } from '@angular/core'; export const BASE_PATH = new InjectionToken('basePath'); export const COLLECTION_FORMATS = { diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts index b23d131cca1..ac63e3a84de 100644 --- a/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts @@ -188,13 +188,13 @@ export class PetApi implements PetApiInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Content-Type header let consumes: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -250,7 +250,7 @@ export class PetApi implements PetApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -299,7 +299,7 @@ export class PetApi implements PetApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -348,7 +348,7 @@ export class PetApi implements PetApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -396,7 +396,7 @@ export class PetApi implements PetApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -440,13 +440,13 @@ export class PetApi implements PetApiInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Content-Type header let consumes: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -502,7 +502,7 @@ export class PetApi implements PetApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -566,7 +566,7 @@ export class PetApi implements PetApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts index dcefb6f6b28..ed76ded48e6 100644 --- a/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts @@ -127,7 +127,7 @@ export class StoreApi implements StoreApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -160,7 +160,7 @@ export class StoreApi implements StoreApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -204,7 +204,7 @@ export class StoreApi implements StoreApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -238,7 +238,7 @@ export class StoreApi implements StoreApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts index b8738b0e463..0bb23fb6c90 100644 --- a/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts @@ -188,7 +188,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -225,7 +225,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -262,7 +262,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -304,7 +304,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -343,7 +343,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -386,7 +386,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -419,7 +419,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; @@ -459,7 +459,7 @@ export class UserApi implements UserApiInterface { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', 'application/xml' ]; diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts index d06561e7dac..6fe58549f39 100644 --- a/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts +++ b/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts @@ -1,4 +1,4 @@ -import { InjectionToken } from '@angular/core'; +import { InjectionToken } from '@angular/core'; export const BASE_PATH = new InjectionToken('basePath'); export const COLLECTION_FORMATS = {