refEnum not handled in query parameter validation
See original GitHub issueSorting
-
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
Expected Behavior
import { Controller, Get, Query, Route, Request } from 'tsoa'
import Koa from 'koa'
type Alert = {id: string}
enum AlertTag {
Foo = 'foo',
Bar = 'bar',
}
@Route('/')
export class AlertsController extends Controller {
@Get('/')
public async getAlerts(
@Request() request: Koa.Request,
@Query() alertTags?: AlertTag[]
): Promise<Alert[]> {
void request, alertTags;
return []
}
}
TSOa should validate query params for the enum values of the array.
curl http://localhost:3000/alerts/\?alertTags\=foobar
should validate query params with
{"fields":{"alertTags.$0":{"message":"should be one of the following; ['foo','bar']","value":"foobar"}}}
Note: I manually edited node_modules/@tsoa/runtime/dist/routeGeneration/templateHelpers.js
to add case refEnum
to generate this error message.
Current Behavior
refEnum
is not handled in src/routeGeneration/templateHelpers.ts
but it’s the type generated in app/routes.ts
file.
Query param alertTags
is not validated.
Possible Solution
Either the refEnum type should be handled in validateParam
as enum
case, or the template generator/metadata parser should change refEnum
to enum
in some cases.
Steps to Reproduce
See repo https://github.com/gpichot/tsoa-refenum-query-param for minimal reproducible example.
Context (Environment)
Version of the library: 3.7.0 Version of NodeJS: 14.16.0
- Confirm you were using yarn not npm: [x]
Detailed Description
I don’t know, but if you have ideas on how to solve this I may find some bandwidth to make a PR.
Breaking change?
I don’t know
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top GitHub Comments
Release v3.8.0 should fix this. Please ping me to reopen if there are any remaining issues.
@WoH thanks for the fix. I tested here https://github.com/gpichot/tsoa-refenum-query-param and it’s working Cheers !