From 438a7d97da1d7e70e554e81886f83160f337e67b Mon Sep 17 00:00:00 2001 From: Silas Boyd-Wickizer Date: Fri, 28 Dec 2018 14:10:04 -0800 Subject: [PATCH] feat(backend): pass Path Item Object to backend --- README.md | 2 +- lib/backends/fetch.js | 2 +- lib/backends/swagger-client.js | 6 +++--- lib/backends/swagger-client.test.js | 3 ++- lib/loader.js | 3 +-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f32e659..a6546ba 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ directly to the API caller. * `options.body` - JSONifable object. * `options.method` - HTTP method. -* `options.operationObject` - Swagger/OpenAPI Operation Object. +* `options.pathItemObject` - Swagger/OpenAPI Path Item Object. * `options.parameters` - named query parameters. * `options.qs` - named query parameters (legacy). * `options.pathname` - URL pathname. diff --git a/lib/backends/fetch.js b/lib/backends/fetch.js index 4bacb4e..900521d 100644 --- a/lib/backends/fetch.js +++ b/lib/backends/fetch.js @@ -19,7 +19,7 @@ class FetchClient { * @param {object} options - options object. * @param {object} options.body - JSONifable object. * @param {string} options.method - HTTP method. - * @param {string} options.operationObject - Swagger/OpenAPI Operation Object. + * @param {string} options.pathItemObject - Swagger/OpenAPI Path Item Object. * @param {object} options.parameters - named query parameters. * @param {object} options.qs - named query parameters (legacy). * @param {string} options.pathname - URL pathname. diff --git a/lib/backends/swagger-client.js b/lib/backends/swagger-client.js index 49ed75a..1de1c29 100644 --- a/lib/backends/swagger-client.js +++ b/lib/backends/swagger-client.js @@ -15,7 +15,7 @@ class SwaggerClient { * @param {object} options - options object. * @param {object} options.body - JSONifable object. * @param {string} options.method - HTTP method. - * @param {string} options.operationObject - Swagger/OpenAPI Operation Object. + * @param {string} options.pathItemObject - Swagger/OpenAPI Path Item Object. * @param {object} options.parameters - named query parameters. * @param {object} options.qs - named query parameters (legacy). * @param {string} options.pathname - URL pathname. @@ -28,9 +28,9 @@ class SwaggerClient { options.qs || options.parameters, options.pathnameParameters ) - + const operationId = options.pathItemObject[options.method.toLowerCase()].operationId return this.client.execute({ - operationId: options.operationObject.operationId, + operationId, parameters }) } diff --git a/lib/backends/swagger-client.test.js b/lib/backends/swagger-client.test.js index 3771d66..ad763e1 100644 --- a/lib/backends/swagger-client.test.js +++ b/lib/backends/swagger-client.test.js @@ -11,7 +11,8 @@ describe('lib.backends.swagger-client', () => { const client = new SwaggerClient({ client: swagger }) client.http({ - operationObject: { operationId: 'getFoo' }, + method: 'GET', + pathItemObject: { get: { operationId: 'getFoo' } }, body: { a: 1 }, parameters: { b: 2 }, pathnameParameters: { c: 3 } diff --git a/lib/loader.js b/lib/loader.js index 1fde666..dba26ef 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -223,10 +223,9 @@ class Component { * @returns {(Promise|Stream)} Promise */ _requestAsync (method, options) { - const operationObject = this.pathItemObject[method.toLowerCase()] return this.backend.http(Object.assign({ method, - operationObject, + pathItemObject: this.pathItemObject, pathname: this.getPath(), pathnameParameters: this.parameters }, options))