Skip to content

Commit

Permalink
Do not replace floating braces
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenquimby committed Dec 14, 2020
1 parent 4977d49 commit b7d5002
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 1 addition & 5 deletions packages/cli/src/utils/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@ export function convertColonPathParams(path: string) {
}

export function convertBracesPathParams(path: string) {
const normalised = path.replace(/{([^\/]+)}/g, ':$1');
if (normalised.indexOf('{') >= 0 || normalised.indexOf('}') >= 0) {
throw new Error(`Invalid parameters found in path: ${path}`);
}
return normalised;
return path.replace(/{([^\/]+)}/g, ':$1');
}
10 changes: 5 additions & 5 deletions tests/unit/swagger/common/paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Braces path params conversion', () => {
expect(convertBracesPathParams('path1/:pathParam')).to.equal('path1/:pathParam');
});

it('should replace "{param}" with ":param" in path', () => {
it('should replace braces params with colon params', () => {
expect(convertBracesPathParams('{pathParam}')).to.equal(':pathParam');
expect(convertBracesPathParams('/path1/{pathParam}')).to.equal('/path1/:pathParam');
expect(convertBracesPathParams('/path1/{pathParam}/path2')).to.equal('/path1/:pathParam/path2');
Expand All @@ -105,9 +105,9 @@ describe('Braces path params conversion', () => {
expect(convertBracesPathParams('')).to.equal('');
});

it('should throw with invalid params', () => {
expect(() => convertBracesPathParams('{')).to.throw();
expect(() => convertBracesPathParams('path}')).to.throw();
expect(() => convertBracesPathParams('/path/{pathParam1}/{pathParam2')).to.throw();
it('should not replace floating braces', () => {
expect(() => convertBracesPathParams('{')).to.equal('{');
expect(() => convertBracesPathParams('path}')).to.equal('path}');
expect(() => convertBracesPathParams('/path/{pathParam1}/{pathParam2')).to.equal('/path/:pathParam/{pathParam2');
});
});

0 comments on commit b7d5002

Please sign in to comment.