Skip to content

Allow to register a route with colon in the path #7147

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

Open
knaoe opened this issue Mar 9, 2021 · 0 comments
Open

Allow to register a route with colon in the path #7147

knaoe opened this issue Mar 9, 2021 · 0 comments
Labels
feature REST Issues related to @loopback/rest package and REST transport in general

Comments

@knaoe
Copy link

knaoe commented Mar 9, 2021

Steps to reproduce

Try to register a route with colon.

export class ItemController {
  ...
  @get('/items:search')
  @response(200)
  async search(): Promise<Item[]> {
    ...
  }
}

Current Behavior

Got error when startup.

Cannot start the application. Error: Invalid path template: '/items:search'. Please use {search} instead of ':search'
    at Object.validateApiPath (/home/node/app/node_modules/@loopback/rest/dist/router/openapi-path.js:30:23)
    at RoutingTable.registerRoute (/home/node/app/node_modules/@loopback/rest/dist/router/routing-table.js:46:24)
    at HttpHandler.registerRoute (/home/node/app/node_modules/@loopback/rest/dist/http-handler.js:22:22)
    at RestServer._createHttpHandler (/home/node/app/node_modules/@loopback/rest/dist/rest.server.js:312:31)
    at RestServer._setupHandlerIfNeeded (/home/node/app/node_modules/@loopback/rest/dist/rest.server.js:268:14)
    at RestServer.start (/home/node/app/node_modules/@loopback/rest/dist/rest.server.js:640:14)
    at invokeTargetMethod (/home/node/app/node_modules/@loopback/context/dist/invocation.js:156:49)
    at /home/node/app/node_modules/@loopback/context/dist/invocation.js:138:16
    at Object.transformValueOrPromise (/home/node/app/node_modules/@loopback/context/dist/value-promise.js:257:16)
    at invokeTargetMethodWithInjection (/home/node/app/node_modules/@loopback/context/dist/invocation.js:133:28)
    at Object.invokeMethod (/home/node/app/node_modules/@loopback/context/dist/invocation.js:106:20)
    at LifeCycleObserverRegistry.invokeObserver (/home/node/app/node_modules/@loopback/core/dist/lifecycle-registry.js:116:29)
    at /home/node/app/node_modules/@loopback/core/dist/lifecycle-registry.js:103:25
    at Array.map (<anonymous>)
    at LifeCycleObserverRegistry.notifyObservers (/home/node/app/node_modules/@loopback/core/dist/lifecycle-registry.js:101:37)
    at LifeCycleObserverRegistry.notifyGroups (/home/node/app/node_modules/@loopback/core/dist/lifecycle-registry.js:147:28)

because of this validation.

https://github.com/strongloop/loopback-next/blob/6423d40f8520f863836af1d64e1c10b1dbc7507e/packages/rest/src/router/openapi-path.ts#L22-L32

Expected Behavior

A path using colon like custom verb for the resource (like /items:serach, /items:move) should be passed the validation.
Google's API design guideline recommends this expression as custom methods.

Additional information

$ node -e 'console.log(process.platform, process.arch, process.versions.node)'
  linux x64 15.8.0
$ npm ls --prod --depth 0 | grep loopback
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- @loopback/[email protected]
+-- [email protected]
@knaoe knaoe added the bug label Mar 9, 2021
@achrinza achrinza added REST Issues related to @loopback/rest package and REST transport in general feature and removed bug labels Mar 11, 2021
@stale stale bot added the stale label Oct 3, 2021
@loopbackio loopbackio deleted a comment from stale bot Oct 3, 2021
@stale stale bot removed the stale label Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature REST Issues related to @loopback/rest package and REST transport in general
Projects
None yet
Development

No branches or pull requests

2 participants