Skip to content

Commit fbfd0ca

Browse files
authored
Merge pull request #1710 from cesco69/args
perf: avoids to create on every request a new object of args
2 parents a6afd4b + daa1dec commit fbfd0ca

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

packages/cli/src/routeGeneration/templates/express.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export function RegisterRoutes(app: Router) {
8181

8282
{{#each controllers}}
8383
{{#each actions}}
84+
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
85+
{{#each parameters}}
86+
{{@key}}: {{{json this}}},
87+
{{/each}}
88+
};
8489
app.{{method}}('{{fullPath}}',
8590
{{#if security.length}}
8691
authenticateMiddleware({{json security}}),
@@ -101,17 +106,12 @@ export function RegisterRoutes(app: Router) {
101106
...(fetchMiddlewares<RequestHandler>({{../name}}.prototype.{{name}})),
102107

103108
async function {{../name}}_{{name}}(request: ExRequest, response: ExResponse, next: any) {
104-
const args: Record<string, TsoaRoute.ParameterSchema> = {
105-
{{#each parameters}}
106-
{{@key}}: {{{json this}}},
107-
{{/each}}
108-
};
109109

110110
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
111111

112112
let validatedArgs: any[] = [];
113113
try {
114-
validatedArgs = templateService.getValidatedArgs({ args, request, response });
114+
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, response });
115115

116116
{{#if ../../iocModule}}
117117
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;

packages/cli/src/routeGeneration/templates/hapi.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export function RegisterRoutes(server: any) {
5959
// ###########################################################################################################
6060
{{#each controllers}}
6161
{{#each actions}}
62+
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
63+
{{#each parameters}}
64+
{{@key}}: {{{json this}}},
65+
{{/each}}
66+
};
6267
server.route({
6368
method: '{{method}}',
6469
path: '{{fullPath}}',
@@ -92,15 +97,10 @@ export function RegisterRoutes(server: any) {
9297
},
9398
{{/if}}
9499
handler: {{#if ../../iocModule}}async {{/if}}function {{../name}}_{{name}}(request: Request, h: ResponseToolkit) {
95-
const args: Record<string, TsoaRoute.ParameterSchema> = {
96-
{{#each parameters}}
97-
{{@key}}: {{{json this}}},
98-
{{/each}}
99-
};
100100

101101
let validatedArgs: any[] = [];
102102
try {
103-
validatedArgs = templateService.getValidatedArgs({ args, request, h });
103+
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, h });
104104
} catch (err) {
105105
const error = err as any;
106106
if (isBoom(error)) {

packages/cli/src/routeGeneration/templates/koa.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export function RegisterRoutes(router: KoaRouter) {
7777

7878
{{#each controllers}}
7979
{{#each actions}}
80+
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
81+
{{#each parameters}}
82+
{{@key}}: {{{json this}}},
83+
{{/each}}
84+
};
8085
router.{{method}}('{{fullPath}}',
8186
{{#if security.length}}
8287
authenticateMiddleware({{json security}}),
@@ -97,15 +102,10 @@ export function RegisterRoutes(router: KoaRouter) {
97102
...(fetchMiddlewares<Middleware>({{../name}}.prototype.{{name}})),
98103

99104
async function {{../name}}_{{name}}(context: Context, next: Next) {
100-
const args: Record<string, TsoaRoute.ParameterSchema> = {
101-
{{#each parameters}}
102-
{{@key}}: {{{json this}}},
103-
{{/each}}
104-
};
105105

106106
let validatedArgs: any[] = [];
107107
try {
108-
validatedArgs = templateService.getValidatedArgs({ args, context, next });
108+
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, context, next });
109109
} catch (err) {
110110
const error = err as any;
111111
error.message ||= JSON.stringify({ fields: error.fields });

0 commit comments

Comments
 (0)