Skip to content

Commit

Permalink
Merge pull request #1710 from cesco69/args
Browse files Browse the repository at this point in the history
perf: avoids to create on every request a new object of args
  • Loading branch information
WoH authored Dec 8, 2024
2 parents a6afd4b + daa1dec commit fbfd0ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/cli/src/routeGeneration/templates/express.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export function RegisterRoutes(app: Router) {

{{#each controllers}}
{{#each actions}}
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};
app.{{method}}('{{fullPath}}',
{{#if security.length}}
authenticateMiddleware({{json security}}),
Expand All @@ -101,17 +106,12 @@ export function RegisterRoutes(app: Router) {
...(fetchMiddlewares<RequestHandler>({{../name}}.prototype.{{name}})),

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

// 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

let validatedArgs: any[] = [];
try {
validatedArgs = templateService.getValidatedArgs({ args, request, response });
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, response });

{{#if ../../iocModule}}
const container: IocContainer = typeof iocContainer === 'function' ? (iocContainer as IocContainerFactory)(request) : iocContainer;
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/routeGeneration/templates/hapi.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export function RegisterRoutes(server: any) {
// ###########################################################################################################
{{#each controllers}}
{{#each actions}}
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};
server.route({
method: '{{method}}',
path: '{{fullPath}}',
Expand Down Expand Up @@ -92,15 +97,10 @@ export function RegisterRoutes(server: any) {
},
{{/if}}
handler: {{#if ../../iocModule}}async {{/if}}function {{../name}}_{{name}}(request: Request, h: ResponseToolkit) {
const args: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};

let validatedArgs: any[] = [];
try {
validatedArgs = templateService.getValidatedArgs({ args, request, h });
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, request, h });
} catch (err) {
const error = err as any;
if (isBoom(error)) {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/routeGeneration/templates/koa.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export function RegisterRoutes(router: KoaRouter) {

{{#each controllers}}
{{#each actions}}
const args{{../name}}_{{name}}: Record<string, TsoaRoute.ParameterSchema> = {
{{#each parameters}}
{{@key}}: {{{json this}}},
{{/each}}
};
router.{{method}}('{{fullPath}}',
{{#if security.length}}
authenticateMiddleware({{json security}}),
Expand All @@ -97,15 +102,10 @@ export function RegisterRoutes(router: KoaRouter) {
...(fetchMiddlewares<Middleware>({{../name}}.prototype.{{name}})),

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

let validatedArgs: any[] = [];
try {
validatedArgs = templateService.getValidatedArgs({ args, context, next });
validatedArgs = templateService.getValidatedArgs({ args: args{{../name}}_{{name}}, context, next });
} catch (err) {
const error = err as any;
error.message ||= JSON.stringify({ fields: error.fields });
Expand Down

0 comments on commit fbfd0ca

Please sign in to comment.