From 78c865e268a87aaaafcd0ce38893b7da60b954cc Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 27 Apr 2018 22:12:30 +0800 Subject: [PATCH] update ts angular2 petstore oas2 (#249) --- .../npm/.openapi-generator/VERSION | 2 +- .../typescript-angular-v2/npm/README.md | 15 +++- .../npm/api/pet.service.ts | 40 ++++------ .../npm/api/store.service.ts | 18 ++--- .../npm/api/user.service.ts | 80 ++++++++----------- .../npm/configuration.ts | 12 +-- .../typescript-angular-v2/npm/package.json | 4 +- .../typescript-angular-v2/npm/tsconfig.json | 6 +- 8 files changed, 84 insertions(+), 93 deletions(-) diff --git a/samples/client/petstore/typescript-angular-v2/npm/.openapi-generator/VERSION b/samples/client/petstore/typescript-angular-v2/npm/.openapi-generator/VERSION index 855ff9501eb..096bf47efe3 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/.openapi-generator/VERSION +++ b/samples/client/petstore/typescript-angular-v2/npm/.openapi-generator/VERSION @@ -1 +1 @@ -2.4.0-SNAPSHOT \ No newline at end of file +3.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v2/npm/README.md b/samples/client/petstore/typescript-angular-v2/npm/README.md index 507613134c5..1d02eea3ae8 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/README.md +++ b/samples/client/petstore/typescript-angular-v2/npm/README.md @@ -2,7 +2,7 @@ ### Building -To build an compile the typescript sources to javascript use: +To install the required dependencies and to build the typescript sources run: ``` npm install npm run build @@ -14,7 +14,7 @@ First build the package than run ```npm publish``` ### consuming -navigate to the folder of your consuming project and run one of next commando's. +Navigate to the folder of your consuming project and run one of next commands. _published:_ @@ -22,7 +22,7 @@ _published:_ npm install @swagger/angular2-typescript-petstore@0.0.1 --save ``` -_unPublished (not recommended):_ +_without publishing (not recommended):_ ``` npm install PATH_TO_GENERATED_PACKAGE --save @@ -37,9 +37,16 @@ npm link In your project: ``` -npm link @swagger/angular2-typescript-petstore@0.0.1 +npm link @swagger/angular2-typescript-petstore ``` +__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. +Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround. +Published packages are not effected by this issue. + + +#### General usage + In your Angular project: diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index 0f487e7b1a0..61eb3fb328a 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -61,10 +61,10 @@ export class PetService { /** * * @summary Add a new pet to the store - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - public addPet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { - return this.addPetWithHttpInfo(body, extraHttpRequestParams) + public addPet(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + return this.addPetWithHttpInfo(pet, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -142,10 +142,10 @@ export class PetService { /** * * @summary Update an existing pet - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - public updatePet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { - return this.updatePetWithHttpInfo(body, extraHttpRequestParams) + public updatePet(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + return this.updatePetWithHttpInfo(pet, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -195,12 +195,12 @@ export class PetService { /** * Add a new pet to the store * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling addPet.'); + public addPetWithHttpInfo(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (pet === null || pet === undefined) { + throw new Error('Required parameter pet was null or undefined when calling addPet.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -215,8 +215,6 @@ export class PetService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -236,7 +234,7 @@ export class PetService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: pet == null ? '' : JSON.stringify(pet), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -274,8 +272,6 @@ export class PetService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -455,12 +451,12 @@ export class PetService { /** * Update an existing pet * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling updatePet.'); + public updatePetWithHttpInfo(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (pet === null || pet === undefined) { + throw new Error('Required parameter pet was null or undefined when calling updatePet.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -475,8 +471,6 @@ export class PetService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -496,7 +490,7 @@ export class PetService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: pet == null ? '' : JSON.stringify(pet), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -532,8 +526,6 @@ export class PetService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index 443d2ba8480..7060b25ad2c 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -107,10 +107,10 @@ export class StoreService { /** * * @summary Place an order for a pet - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet */ - public placeOrder(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { - return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) + public placeOrder(order: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { + return this.placeOrderWithHttpInfo(order, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -136,8 +136,6 @@ export class StoreService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -244,12 +242,12 @@ export class StoreService { /** * Place an order for a pet * - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling placeOrder.'); + public placeOrderWithHttpInfo(order: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (order === null || order === undefined) { + throw new Error('Required parameter order was null or undefined when calling placeOrder.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -275,7 +273,7 @@ export class StoreService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: order == null ? '' : JSON.stringify(order), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts index 04225a20df6..6d30cffe990 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts @@ -60,10 +60,10 @@ export class UserService { /** * This can only be done by the logged in user. * @summary Create user - * @param body Created user object + * @param user Created user object */ - public createUser(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { - return this.createUserWithHttpInfo(body, extraHttpRequestParams) + public createUser(user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + return this.createUserWithHttpInfo(user, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -76,10 +76,10 @@ export class UserService { /** * * @summary Creates list of users with given input array - * @param body List of user object + * @param user List of user object */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { - return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) + public createUsersWithArrayInput(user: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + return this.createUsersWithArrayInputWithHttpInfo(user, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -92,10 +92,10 @@ export class UserService { /** * * @summary Creates list of users with given input array - * @param body List of user object + * @param user List of user object */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { - return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) + public createUsersWithListInput(user: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + return this.createUsersWithListInputWithHttpInfo(user, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -173,10 +173,10 @@ export class UserService { * This can only be done by the logged in user. * @summary Updated user * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object */ - public updateUser(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { - return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) + public updateUser(username: string, user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + return this.updateUserWithHttpInfo(username, user, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { return undefined; @@ -190,20 +190,18 @@ export class UserService { /** * Create user * This can only be done by the logged in user. - * @param body Created user object + * @param user Created user object */ - public createUserWithHttpInfo(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling createUser.'); + public createUserWithHttpInfo(user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (user === null || user === undefined) { + throw new Error('Required parameter user was null or undefined when calling createUser.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -221,7 +219,7 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -235,20 +233,18 @@ export class UserService { /** * Creates list of users with given input array * - * @param body List of user object + * @param user List of user object */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); + public createUsersWithArrayInputWithHttpInfo(user: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (user === null || user === undefined) { + throw new Error('Required parameter user was null or undefined when calling createUsersWithArrayInput.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -266,7 +262,7 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -280,20 +276,18 @@ export class UserService { /** * Creates list of users with given input array * - * @param body List of user object + * @param user List of user object */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); + public createUsersWithListInputWithHttpInfo(user: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (user === null || user === undefined) { + throw new Error('Required parameter user was null or undefined when calling createUsersWithListInput.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -311,7 +305,7 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -337,8 +331,6 @@ export class UserService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -418,10 +410,10 @@ export class UserService { } let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - if (username !== undefined) { + if (username !== undefined && username !== null) { queryParameters.set('username', username); } - if (password !== undefined) { + if (password !== undefined && password !== null) { queryParameters.set('password', password); } @@ -466,8 +458,6 @@ export class UserService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -495,23 +485,21 @@ export class UserService { * Updated user * This can only be done by the logged in user. * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object */ - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { + public updateUserWithHttpInfo(username: string, user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - if (body === null || body === undefined) { - throw new Error('Required parameter body was null or undefined when calling updateUser.'); + if (user === null || user === undefined) { + throw new Error('Required parameter user was null or undefined when calling updateUser.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/xml', - 'application/json' ]; const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); if (httpHeaderAcceptSelected != undefined) { @@ -529,7 +517,7 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612 withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular-v2/npm/configuration.ts b/samples/client/petstore/typescript-angular-v2/npm/configuration.ts index 2ee1824f5f7..82e8458f39e 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/configuration.ts @@ -28,8 +28,8 @@ export class Configuration { * Select the correct content-type to use for a request. * Uses {@link Configuration#isJsonMime} to determine the correct content-type. * If no content type is found return the first found type if the contentTypes is not empty - * @param {string[]} contentTypes - the array of content types that are available for selection - * @returns {string} the selected content-type or undefined if no selection could be made. + * @param contentTypes - the array of content types that are available for selection + * @returns the selected content-type or undefined if no selection could be made. */ public selectHeaderContentType (contentTypes: string[]): string | undefined { if (contentTypes.length == 0) { @@ -47,8 +47,8 @@ export class Configuration { * Select the correct accept content-type to use for a request. * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. * If no content type is found return the first found type if the contentTypes is not empty - * @param {string[]} accepts - the array of content types that are available for selection. - * @returns {string} the selected content-type or undefined if no selection could be made. + * @param accepts - the array of content types that are available for selection. + * @returns the selected content-type or undefined if no selection could be made. */ public selectHeaderAccept(accepts: string[]): string | undefined { if (accepts.length == 0) { @@ -69,8 +69,8 @@ export class Configuration { * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json - * @param {string} mime - MIME (Multipurpose Internet Mail Extensions) - * @return {boolean} True if the given MIME is JSON, false otherwise. + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. */ public isJsonMime(mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); diff --git a/samples/client/petstore/typescript-angular-v2/npm/package.json b/samples/client/petstore/typescript-angular-v2/npm/package.json index 0e363919a9b..3991f96afcd 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/package.json +++ b/samples/client/petstore/typescript-angular-v2/npm/package.json @@ -8,9 +8,10 @@ ], "license": "Unlicense", "main": "dist/index.js", + "module": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "build": "tsc --outDir dist/", + "build": "ngc", "postinstall": "npm run build" }, "peerDependencies": { @@ -24,6 +25,7 @@ "zone.js": "^0.7.6" }, "devDependencies": { + "@angular/compiler-cli": "^2.0.0", "@angular/core": "^2.0.0", "@angular/http": "^2.0.0", "@angular/common": "^2.0.0", diff --git a/samples/client/petstore/typescript-angular-v2/npm/tsconfig.json b/samples/client/petstore/typescript-angular-v2/npm/tsconfig.json index 498ee01e9dd..3983fa8d99c 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/tsconfig.json +++ b/samples/client/petstore/typescript-angular-v2/npm/tsconfig.json @@ -21,5 +21,9 @@ "filesGlob": [ "./model/*.ts", "./api/*.ts" - ] + ], + "angularCompilerOptions": { + "genDir": "dist", + "skipTemplateCodegen": true + } }