Skip to content

Commit

Permalink
fix: getOperation not returning a full object with uri templates (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Jun 18, 2020
1 parent aa99226 commit e031410
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/tooling/__tests__/lib/get-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const petstore = require('../__fixtures__/petstore.json');

const swagger = new Oas(petstore);

describe('getSchema', () => {
describe('getPath', () => {
it('should return path from swagger file', () => {
const doc = { swagger: { path: '/user/logout' }, api: { method: 'get' } };

Expand Down
12 changes: 11 additions & 1 deletion packages/tooling/__tests__/oas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('#getOperation()', () => {
const res = oas.getOperation(uri, method);

expect(res).toBeInstanceOf(Operation);
expect(res.path).toBe('/pet/:petId');
expect(res.path).toBe('/pet/{petId}');
expect(res.method).toBe('delete');
});

Expand All @@ -229,6 +229,16 @@ describe('#getOperation()', () => {
const res = oas.getOperation('http://petstore.swagger.io/v2/pet', 'put');
expect(res.getSecurity()).toStrictEqual(security);
});

it('should handle paths with uri templates', () => {
const oas = new Oas(petstore);
const operation = oas.getOperation('http://petstore.swagger.io/v2/store/order/1234', 'get');

expect(operation.parameters).toHaveLength(1);
expect(operation.operationId).toBe('getOrderById');
expect(operation.path).toBe('/store/order/{orderId}');
expect(operation.method).toBe('get');
});
});

describe('server variables', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tooling/src/oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Oas {
return undefined;
}

return this.operation(op.url.path, method);
return this.operation(op.url.nonNormalizedPath, method);
}
}

Expand Down

0 comments on commit e031410

Please sign in to comment.