Please Add `optional: boolean` to @Query route param decorator
See original GitHub issueI’m submitting a…
[x] Feature request
Current behavior
Using @Query('foo')
will always make a query parameter required.
Expected behavior
The Query decorator should have an optional: boolean
property available, similar to how the Args decorator for gql resolvers has nullable and other options.
e.g.
@Query({ name: 'foo', optional: true })
I’m ok with it always being a string and then using pipes to validate / transform the value downstream but at least nullable
or optional
, whatever, would be nice.
Minimal reproduction of the problem with instructions
NA
What is the motivation / use case for changing the behavior?
I’m creating a controller and would like to have optional parameters with sensible defaults.
Environment
NA
Extra
I believe this is the correct location in code: https://github.com/nestjs/nest/blob/master/packages/common/decorators/http/route-params.decorator.ts#L95
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
how to use optional url parameters with NestjS - Stack Overflow
Opinion: You can use query params if the params are optional. It is never a good idea to create optional param routes (disagreements...
Read more >Optional Parameters in ASP.NET Core Web API Routing
We can make a route parameter optional by adding “?” to it. The only gimmick is while declaring a route parameter as optional,...
Read more >Controllers | NestJS - A progressive Node.js framework
The route path for a handler is determined by concatenating the (optional) prefix declared for the controller, and any path specified in the...
Read more >Decorators | tsoa - GitHub Pages
Use on @Query parameters to exclude query params from the generated OpenAPI Specification document. The parameter must either allow undefined or have a...
Read more >typing — Support for type hints — Python 3.11.1 documentation
Subtypes are accepted as arguments. New features are frequently added to the typing module. The typing_extensions package provides backports of these new ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@justinmchase
Both solutions are fine 😃