@Hidden + @Query makes the query param `undefined`
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
- Print out:
foo
- 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
- Define a controller
- Define an endpoint with a query param that's decorated with both
@Query()and@Hidden() - 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
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.👀
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
This issue still occurs and should be re-opened.
@grvrossmack I'm repoening this as it seems like you may be interested in fixing this?
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
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.