Skip to content

Commit

Permalink
feat(rest): allow - to be used for path template variable names
Browse files Browse the repository at this point in the history
Some specs use `{account-id}` as part of the path.
  • Loading branch information
raymondfeng committed Apr 10, 2019
1 parent 1877727 commit 7fc2800
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/rest/src/__tests__/unit/router/openapi-path.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';

import {validateApiPath} from '../../..';

describe('validateApiPath', () => {
Expand Down Expand Up @@ -42,6 +41,16 @@ 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}');
});

it('disallows /:foo/bar', () => {
disallows('/:foo/bar');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/router/openapi-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import pathToRegExp = require('path-to-regexp');
* allows `[A-Za-z0-9_]`
*/
const POSSIBLE_VARNAME_PATTERN = /\{([^\}]+)\}/g;
const INVALID_VARNAME_PATTERN = /\{([^\}]*[^\w\}][^\}]*)\}/;
const INVALID_VARNAME_PATTERN = /\{([^\}]*[^\w\-\}][^\}]*)\}/;

/**
* Validate the path to be compatible with OpenAPI path template. No parameter
Expand Down

0 comments on commit 7fc2800

Please sign in to comment.