Skip to content

Commit

Permalink
Fix splitPath url regex to support single character params
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
Dom Harrington committed Jun 5, 2018
1 parent dc7c99f commit 75311ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/api-explorer/__tests__/PathUrl.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const { shallow } = require('enzyme');
const PathUrl = require('../src/PathUrl');
const Oas = require('../src/lib/Oas');

const { splitPath } = PathUrl;

const { Operation } = Oas;
const petstore = require('./fixtures/petstore/oas');

Expand Down Expand Up @@ -76,3 +78,12 @@ test('button click should call onSubmit', () => {

expect(called).toBe(true);
});

describe('splitPath()', () => {
test('should work for multiple path params', () => {
expect(splitPath('/{a}/{b}/c').length).toBe(5);
expect(splitPath('/v1/flight/{FlightID}/sitezonetargeting/{SiteZoneTargetingID}').length).toBe(
4,
);
});
});
2 changes: 1 addition & 1 deletion packages/api-explorer/dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/api-explorer/src/PathUrl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const extensions = require('@readme/oas-extensions');

function splitPath(path) {
return path
.split(/({\w.+?})/)
.split(/({.+?})/)
.filter(Boolean)
.map(part => {
return { type: part.match(/[{}]/) ? 'variable' : 'text', value: part.replace(/[{}]/g, '') };
Expand Down Expand Up @@ -107,3 +107,4 @@ PathUrl.defaultProps = {
apiKey: '',
};
module.exports = PathUrl;
module.exports.splitPath = splitPath;

0 comments on commit 75311ec

Please sign in to comment.