diff --git a/packages/rest/src/__tests__/unit/router/openapi-path.unit.ts b/packages/rest/src/__tests__/unit/router/openapi-path.unit.ts index dc377bd887ad..31d66fe01e99 100644 --- a/packages/rest/src/__tests__/unit/router/openapi-path.unit.ts +++ b/packages/rest/src/__tests__/unit/router/openapi-path.unit.ts @@ -4,7 +4,6 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from '@loopback/testlab'; - import {validateApiPath} from '../../..'; describe('validateApiPath', () => { @@ -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'); }); diff --git a/packages/rest/src/router/openapi-path.ts b/packages/rest/src/router/openapi-path.ts index c88c839f79c4..f4f1d7c97e5f 100644 --- a/packages/rest/src/router/openapi-path.ts +++ b/packages/rest/src/router/openapi-path.ts @@ -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