diff --git a/lib/backends/swagger-client.js b/lib/backends/swagger-client.js index 1de1c29..dd061c8 100644 --- a/lib/backends/swagger-client.js +++ b/lib/backends/swagger-client.js @@ -28,11 +28,17 @@ class SwaggerClient { options.qs || options.parameters, options.pathnameParameters ) + const operationId = options.pathItemObject[options.method.toLowerCase()].operationId - return this.client.execute({ - operationId, - parameters - }) + + const operationReference = operationId ? { + operationId + } : { + pathName: options.pathname, + method: options.method + } + + return this.client.execute(Object.assign({}, operationReference, { parameters })) } } diff --git a/lib/backends/swagger-client.test.js b/lib/backends/swagger-client.test.js index ad763e1..d550d2e 100644 --- a/lib/backends/swagger-client.test.js +++ b/lib/backends/swagger-client.test.js @@ -27,7 +27,33 @@ describe('lib.backends.swagger-client', () => { } })).to.be.equal(true) done() - }) + }).catch(done) + }) + + it('executes operation without operationId', done => { + const swagger = { execute: sinon.spy(() => Promise.resolve('some result')) } + const client = new SwaggerClient({ client: swagger }) + + client.http({ + method: 'GET', + pathname: '/api/v2/foo', + pathItemObject: { get: { } }, + body: { a: 1 }, + parameters: { b: 2 }, + pathnameParameters: { c: 3 } + }).then(() => { + expect(swagger.execute.called).is.equal(true) + expect(swagger.execute.getCall(0).args).to.deep.equal([{ + pathName: '/api/v2/foo', + method: 'GET', + parameters: { + a: 1, + b: 2, + c: 3 + } + }]) + done() + }).catch(done) }) }) }) diff --git a/lib/loader.js b/lib/loader.js index 983bc60..76d5b53 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -220,7 +220,6 @@ class Component { // "Expose" operations by omitting the leading _ from the method name. // Object.keys(endpoint.pathItem) - .filter(key => endpoint.pathItem[key].operationId) .forEach(method => { component[method] = component['_' + method] if (method === 'get') component.getStream = component._getStream diff --git a/lib/loader.test.js b/lib/loader.test.js index 5ae6108..1e8980c 100644 --- a/lib/loader.test.js +++ b/lib/loader.test.js @@ -88,6 +88,21 @@ describe('list.loader', () => { expect(component.foo('loo').bar.getPath()).to.equal('/foo/loo/bar') }) + it('does not blow up without operationId', () => { + const spec = { + paths: { + '/apis/some/url': { + get: { + } + } + } + } + const component = new Component() + component._addSpec(spec) + expect(component.apis.some.url.get).is.a('function') + expect(component.apis.some.url.getStream).is.a('function') + }) + it('tracks parameters correctly', () => { const spec = { paths: {