Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest): allow - to be used for path template variable names #2724

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid OpenAPI path? Will our two router implementations correctly handle such path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. It turns out that - is not allowed by path-to-regexp as it does not match \w. I'll investigate more.

});

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