Skip to content

Commit

Permalink
fix: findOperation issues with "/" paths (#223)
Browse files Browse the repository at this point in the history
* fix: findOperation issues with "/" paths

* test: add check for res.operation

feedback: #223 (comment)
  • Loading branch information
kanadgupta authored Jul 16, 2020
1 parent a6ae8cc commit ca1cad2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 42 additions & 0 deletions packages/tooling/__tests__/oas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,48 @@ describe('#findOperation()', () => {
});
});

it('should return result if path is slash', () => {
const oas = new Oas({
openapi: '3.0.0',
servers: [
{
url: 'https://example.com',
},
],
paths: {
'/': {
get: {
responses: {
'200': {
description: 'OK',
},
},
},
},
},
});

const uri = 'https://example.com';
const method = 'get';

const res = oas.findOperation(uri, method);
expect(res.url).toStrictEqual({
origin: 'https://example.com',
path: '/',
nonNormalizedPath: '/',
slugs: {},
method: 'GET',
});

expect(res.operation).toStrictEqual({
responses: {
'200': {
description: 'OK',
},
},
});
});

it('should return result if in server variable defaults', () => {
const oas = new Oas(serverVariables);
const uri = 'https://demo.example.com:443/v2/post';
Expand Down
3 changes: 2 additions & 1 deletion packages/tooling/src/oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ class Oas {
if (!targetServer) return undefined;
targetServer.url = this.replaceUrl(targetServer.url, targetServer.variables || {});

const [, pathName] = url.split(targetServer.url);
let [, pathName] = url.split(targetServer.url);
if (pathName === undefined) return undefined;
if (pathName === '') pathName = '/';
const annotatedPaths = generatePathMatches(paths, pathName, targetServer.url);
if (!annotatedPaths.length) return undefined;

Expand Down

0 comments on commit ca1cad2

Please sign in to comment.