From bd240f583f3ef158b6fac04e14b470a32cae9e1b Mon Sep 17 00:00:00 2001 From: Vojtech Masek Date: Mon, 12 Mar 2018 20:58:52 +0100 Subject: [PATCH] feat(api-client): support for head, options and patch http methods Signed-off-by: Vojtech Masek --- src/parser.ts | 4 ++-- templates/ngx-service.mustache | 14 ++++++++++---- tests/esquare/api/api-client.service.ts | 14 ++++++++++---- tests/gcloud-firestore/api/api-client.service.ts | 14 ++++++++++---- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 5e346c4b..0b072936 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -31,12 +31,12 @@ export function createMustacheViewModel(swagger: Swagger): MustacheData { } function parseMethods({paths, security, parameters}: Swagger): Method[] { - const authorizedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']; + const supportedMethods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT']; return [].concat.apply([], Object.entries(paths) .map(([pathName, apiPath]) => Object.entries(apiPath) .filter(([methodType,]) => // tslint:disable-line:whitespace - authorizedMethods.indexOf(methodType.toUpperCase()) !== -1 // skip unsupported methods + supportedMethods.indexOf(methodType.toUpperCase()) !== -1 // skip unsupported methods ) .map(([methodType, operation]) => ({ path: pathName.replace(/({.*?})/g, '$$$1'), // turn path interpolation `{this}` into string template `${this} diff --git a/templates/ngx-service.mustache b/templates/ngx-service.mustache index 9b7983df..9e6439f6 100644 --- a/templates/ngx-service.mustache +++ b/templates/ngx-service.mustache @@ -68,14 +68,20 @@ export class APIClient { {{/methods}} private sendRequest(method: string, path: string, options: HttpOptions, body?: any): Observable { switch (method) { + case 'DELETE': + return this.http.delete(`${this.domain}${path}`, options); case 'GET': return this.http.get(`${this.domain}${path}`, options); - case 'PUT': - return this.http.put(`${this.domain}${path}`, body, options); + case 'HEAD': + return this.http.head(`${this.domain}${path}`, options); + case 'OPTIONS': + return this.http.options(`${this.domain}${path}`, options); + case 'PATCH': + return this.http.patch(`${this.domain}${path}`, body, options); case 'POST': return this.http.post(`${this.domain}${path}`, body, options); - case 'DELETE': - return this.http.delete(`${this.domain}${path}`, options); + case 'PUT': + return this.http.put(`${this.domain}${path}`, body, options); default: console.error(`Unsupported request: ${method}`); return Observable.throw(`Unsupported request: ${method}`); diff --git a/tests/esquare/api/api-client.service.ts b/tests/esquare/api/api-client.service.ts index afddc60d..0f0f8ae0 100644 --- a/tests/esquare/api/api-client.service.ts +++ b/tests/esquare/api/api-client.service.ts @@ -551,14 +551,20 @@ export class APIClient { private sendRequest(method: string, path: string, options: HttpOptions, body?: any): Observable { switch (method) { + case 'DELETE': + return this.http.delete(`${this.domain}${path}`, options); case 'GET': return this.http.get(`${this.domain}${path}`, options); - case 'PUT': - return this.http.put(`${this.domain}${path}`, body, options); + case 'HEAD': + return this.http.head(`${this.domain}${path}`, options); + case 'OPTIONS': + return this.http.options(`${this.domain}${path}`, options); + case 'PATCH': + return this.http.patch(`${this.domain}${path}`, body, options); case 'POST': return this.http.post(`${this.domain}${path}`, body, options); - case 'DELETE': - return this.http.delete(`${this.domain}${path}`, options); + case 'PUT': + return this.http.put(`${this.domain}${path}`, body, options); default: console.error(`Unsupported request: ${method}`); return Observable.throw(`Unsupported request: ${method}`); diff --git a/tests/gcloud-firestore/api/api-client.service.ts b/tests/gcloud-firestore/api/api-client.service.ts index e2de1fc4..b474061f 100644 --- a/tests/gcloud-firestore/api/api-client.service.ts +++ b/tests/gcloud-firestore/api/api-client.service.ts @@ -203,14 +203,20 @@ export class APIClient { private sendRequest(method: string, path: string, options: HttpOptions, body?: any): Observable { switch (method) { + case 'DELETE': + return this.http.delete(`${this.domain}${path}`, options); case 'GET': return this.http.get(`${this.domain}${path}`, options); - case 'PUT': - return this.http.put(`${this.domain}${path}`, body, options); + case 'HEAD': + return this.http.head(`${this.domain}${path}`, options); + case 'OPTIONS': + return this.http.options(`${this.domain}${path}`, options); + case 'PATCH': + return this.http.patch(`${this.domain}${path}`, body, options); case 'POST': return this.http.post(`${this.domain}${path}`, body, options); - case 'DELETE': - return this.http.delete(`${this.domain}${path}`, options); + case 'PUT': + return this.http.put(`${this.domain}${path}`, body, options); default: console.error(`Unsupported request: ${method}`); return Observable.throw(`Unsupported request: ${method}`);