Custom method decorator
See original GitHub issueHi, Im created a custom decorator for the controller method, this decorator print the function arguments and the result.
Issue: Swagger lose the query parameters
Minimal reproduction of the problem with instructions
import { Controller, Get, Query, Logger } from '@nestjs/common';
import { ApiModelPropertyOptional } from '@nestjs/swagger';
export const PrintLog = (target, name, descriptor) => {
const className = target.constructor.name;
const original = descriptor.value;
descriptor.value = function(...args) {
Logger.log(
`Call with args: ${JSON.stringify(args)}`,
`${className}#${name}`,
);
const result = original.apply(this, args);
Logger.log(`Return: ${JSON.stringify(result)}`, `${className}#${name}`);
return result;
};
};
export class HelloDto {
@ApiModelPropertyOptional()
readonly name?: string;
}
@Controller()
export class AppController {
@Get()
@PrintLog
getHello(@Query() input: HelloDto): string {
return `Hello World! ${input.name}`;
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Custom Method Decorators In Angular — A HTTP Cache ...
In Angular, Decorators are Normal Function which should be returning another function to be called. There are few types of decorators like Class...
Read more >Angular - Custom method decorator which triggers console ...
A method decorator does exactly what you want to do. It intercepts the call of the decorated method. So you are able to...
Read more >Documentation - Decorators - TypeScript
If we want to customize how a decorator is applied to a declaration, we can write a decorator factory. A Decorator Factory is...
Read more >Building custom typescript decorators for angular
As mentioned earlier, decorators are actually just functions, it's as simple as that, and are called with whatever they are decorating. A method...
Read more >How To Use Decorators in TypeScript - DigitalOcean
For a decorator called @decoratorA , you tell TypeScript it should call the function decoratorA . The decoratorA function will be called with ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@creaux Use middleware it’s a solution for this issue but I solved this issue using Javascript Proxy
With Javascript Proxy I can override a
descriptor.value
and SwaggerModule would be able to access the metadata defined on the method.This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.