Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
fix: remove requirement for operationId (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flydiverny authored Apr 29, 2020
1 parent 2b0f778 commit bf5cbf7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/backends/swagger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}
}

Expand Down
28 changes: 27 additions & 1 deletion lib/backends/swagger-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
1 change: 0 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit bf5cbf7

Please sign in to comment.