Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom parameters in controller #1607

Open
2 of 4 tasks
SwagiWagi opened this issue Apr 8, 2024 · 4 comments
Open
2 of 4 tasks

Custom parameters in controller #1607

SwagiWagi opened this issue Apr 8, 2024 · 4 comments

Comments

@SwagiWagi
Copy link

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

I want to be able to have middlewares add custom parameters to my controller, for example:

const addCustomParamMiddleware = (req: express.Request, res: express.Response, next: nextFuncType) => {
  req.locals.tsoaCustomParams = {
    requestId: req.headers["x-request-id"]
  }

  next();
}

@middlwares(addCustomParamMiddleware)
@Get("{screenName}/details")
  public async details(@Path() screenName: string, @CustomParam("requestId") requestId: string): Promise<any> {
    //logic
  }
}

app.use(addCustomParamMiddleware);
registerRoutes(app);
Copy link

github-actions bot commented May 9, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label May 9, 2024
@SwagiWagi
Copy link
Author

up

@WoH
Copy link
Collaborator

WoH commented May 10, 2024

If you are using decorators, you can use https://tsoa-community.github.io/reference/functions/tsoa.Inject.html

and do something like fn(@Inject() @MyDecorator() injectedArg)

Otherwise you can set it in the Middleware and use @Request

@JasonGore
Copy link

Are there any examples of how to implement a custom decorator like @MyDecorator? I've been searching but haven't found one yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants