koa-swagger-decorator
koa-swagger-decorator copied to clipboard
Controller resets on each request
On each request that is made, the controller class is being called new which resets all the properties within it. Using the example within the repo, for each request that is made to the class EggRouter, it will call the constructor. How can I keep the EggRouter from creating a new instance on each request? Thanks!
import { request, summary, tags, query, body, prefix } from '../../../lib';
const tag = tags(['Egg']);
@prefix('/egg')
export default class EggRouter {
constructor(){
console.log('this is being called')
}
@request('get', '/method1')
@summary('egg-like controller method1')
@tag
@query({
no: { type: 'string', description: 'nonono' }
})
async method1(ctx) {
const { no } = ctx.validatedQuery;
ctx.body = this.test;
}
@request('post', '/method2')
@summary('egg-like controller method2')
@tag
@body({
yes: {
type: 'string',
require: true,
description: 'yesyesyes',
nullable: true
}
})
async method2(ctx) {
const { yes } = ctx.validatedBody;
ctx.body = 'updated';
}
}