Skip to content

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

Open
@knaoe

Description

@knaoe

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    RESTIssues related to @loopback/rest package and REST transport in generalfeature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions