loopbackio / loopbackio/loopback-next

Allow to register a route with colon in the path

Open
#7,147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature REST
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

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/boot@3.2.1
+-- @loopback/core@2.14.1
+-- @loopback/repository@3.4.1
+-- @loopback/rest-explorer@3.1.0
+-- @loopback/rest@9.1.3
+-- @loopback/service-proxy@3.0.7
+-- loopback-connector-rest@3.7.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/rest/src/router/openapi-path.ts at validateApiPath, which the issue identifies as rejecting colon-based paths. Check how the validation handles custom-method paths such as /items:search and verify that valid colon paths no longer cause application startup to fail.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.