tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

@Hidden + @Query makes the query param `undefined`

Open rleonr93 opened this issue 4 years ago • 6 comments

Sorting

  • I'm submitting a ...

    • [X] bug report
    • [ ] feature request
    • [ ] support request
  • I confirm that I

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

Expected Behavior

Example shown in docs does not work as expected. Even simpler scenarios won't work as expected:

  @Get()
  public async find(
    @Query() normalParam: string,
    @Query() @Hidden() defaultSecret?: string,
  ): Promise<any> {
    console.log(defaultSecret)
  }

If we make a PUT request with the query param ?defaultSecret=foo Should

  1. Print out:
  foo
  1. and omit the query param from the Swagger docs.

Current Behavior

Console prints out:

  undefined

The query param is indeed hidden from the Swagger docs

Possible Solution

Decorating using @Query() @Hidden() should hide the param from Swagger but still allow to read it as it's sent on the request

Steps to Reproduce

  1. Define a controller
  2. Define an endpoint with a query param that's decorated with both @Query() and @Hidden()
  3. Log the query param from an incoming request. The param always shows up as undefined

Context (Environment)

Version of the library: 3.14.1 Version of NodeJS: 14.18.1

  • Confirm you were using yarn not npm: [X]

Detailed Description

As described above, a query param that's decorated with both @Query() and @Hidden() should be able to be accessed within the code but hidden on Swagger

rleonr93 avatar Jan 20 '22 04:01 rleonr93

Hello there Manghud 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

github-actions[bot] avatar Jan 20 '22 04:01 github-actions[bot]

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[bot] avatar Feb 20 '22 00:02 github-actions[bot]

This issue still occurs and should be re-opened.

grvrossmack avatar Jun 01 '22 03:06 grvrossmack

@grvrossmack I'm repoening this as it seems like you may be interested in fixing this?

WoH avatar Jun 01 '22 08:06 WoH

Using Hidden decorator at parameter would make it not output with spec generate. Thus, the route generate would find nothing.

I think it requires a more complex approach to achieve the goal that not showing in swagger but appearing in route generate. Right? @WoH

jackey8616 avatar Jan 30 '23 06:01 jackey8616

I've never been a fan of modifying parameters (and thus diverging from the runtime behaviour). I think this should be done outside of tsoa (i.e. by post-processing the spec). But I recognise that this is a requested feature so I would've accepted a PR. I think we could flag Parameters as hidden and only affect the spec generator.

WoH avatar Jan 30 '23 07:01 WoH