Skip to content

Commit

Permalink
fix(rest): make it compatible with path-to-regexp@3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Jan 31, 2019
1 parent d3f316c commit ab2b920
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/rest/src/router/openapi-path.ts
Expand Up @@ -42,7 +42,11 @@ export function validateApiPath(path: string = '/') {
// Such as /(.*)
throw new Error(`Unnamed parameter is not allowed in path '${path}'`);
}
if (token.optional || token.repeat || token.pattern !== '[^\\/]+?') {
if (
(token.optional || token.repeat || token.pattern !== '[^\\/]+?') &&
// Required by path-to-regexp@3.x
token.prefix === '/'
) {
// Such as /:foo*, /:foo+, /:foo?, or /:foo(\\d+)
throw new Error(`Parameter modifier is not allowed in path '${path}'`);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/rest/test/unit/router/openapi-path.unit.ts
Expand Up @@ -32,6 +32,11 @@ describe('validateApiPath', () => {
expect(path).to.eql('/{foo}@{bar}');
});

it('allows /{foo}#{bar}', () => {
const path = validateApiPath('/{foo}#{bar}');
expect(path).to.eql('/{foo}#{bar}');
});

it('allows /{_foo}/{bar}', () => {
const path = validateApiPath('/{_foo}/{bar}');
expect(path).to.eql('/{_foo}/{bar}');
Expand Down

0 comments on commit ab2b920

Please sign in to comment.