Skip to content

Custom method decorator in the controller method breaks nestjs route decorators #1180

@andrew-yustyk

Description

@andrew-yustyk

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm using nestjs-config in the current project. It provides method and parameter decorators for own config service (readme). It's @Configurable() decorator replaces method's descriptor.value with own function (source) and seems like this decorator breaks nestjs route decorator when it is located before these decorators. But all works fine when it is placed on the last place.

Broken example:

@Controller('cats')
export class CatsController {
  constructor() {}

  @Configurable()    // <-- custom decorator at the top of order.
  @Get('view')    // <-- nestjs decorator won't work
  @UseInterceptors(ImageInterceptor)    // <-- nestjs decorator won't work
  public async getMostLikedPosts(@ConfigParam('cats.limit') @Query('page') page: number): Cat[] {
     // ... some implementation.
  }
}

Broken example 2:

@Controller('cats')
export class CatsController {
  constructor() {}

  
  @Get('view')    // <-- nestjs decorator will work fine
  @Configurable()    // <-- custom decorator in the middle of order.
  @UseInterceptors(ImageInterceptor)    // <-- nestjs decorator won't work
  public async getMostLikedPosts(@ConfigParam('cats.limit') @Query('page') page: number): Cat[] {
     // ... some implementation.
  }
}

Working example:

@Controller('cats')
export class CatsController {
  constructor() {}
  
  @Get('view')    // <-- nestjs decorator will work fine
  @UseInterceptors(ImageInterceptor)    // <-- nestjs decorator will work fine
  @Configurable()    // <-- custom decorator at the bottom of order
  public async getMostLikedPosts(@ConfigParam('cats.sort') sort: string, @Query('page') page: number, @Query('limit') limit: number): Promise<Post[]> {
     // ... some implementation.
  }
}

Expected behavior

Custom decorators do not break break nestjs or described behavior is well documented.

Environment


Nest version: 5.3.11

For Tooling issues:
- Node version: 8.11.3 and 10
- Platform:  Linux, Ubuntu 16.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions