Skip to content

safe route params

github-actions[bot] edited this page Apr 7, 2024 · 5 revisions

Ensure safe usage of the @Param decorator (nestjs-pedantic/safe-route-params)

💼 This rule is enabled in the following configs: 🌐 all, ✅ recommended.

💡 This rule is manually fixable by editor suggestions.

Rule Details

Incorrect code:

@Controller("user")
class UserController {
  @Get("route/:id")
  getRouteById(@Param("invalid") invalid: string) {}

  notARoute(@Param("id") id: string) {}
}

Corrrect code:

@Controller("user")
class UserController {
  @Get("route/:id")
  getRouteById(@Param("id") invalid: string) {}

  notARoute(id: string) {}
  // OR
  @Post("route/:id")
  notARoute(@Param("id") id: string) {}
}