question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

refEnum not handled in query parameter validation

See original GitHub issue

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

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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
WoHcommented, May 16, 2021

Release v3.8.0 should fix this. Please ping me to reopen if there are any remaining issues.

0reactions
gpichotcommented, May 17, 2021

@WoH thanks for the fix. I tested here https://github.com/gpichot/tsoa-refenum-query-param and it’s working Cheers !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query parameter validation not running · Issue #1314 - GitHub
If I call the base get url, the validation kicks in and notifies me of the missing parameter but for the custom get...
Read more >
Validate query parameters without using a model in .netcore api
From Asp.Net Core 2.1 there is a built-in parameter [BindRequired] which is doing this validation automatically.
Read more >
Spring Boot request parameters validation - Wim Deblauwe
As an example, we'll show a system that handles tasks that need to be executed. There is an endpoint at /tasks that allows...
Read more >
Request Handling — Connexion 2020.0.dev1 documentation
Connexion validates incoming requests for conformance with the schemas described in swagger specification. Request parameters will be provided to the handler ...
Read more >
Validating RequestParams and PathVariables in Spring
Learn how to validate request parameters and path variables with Spring ... we'll use a custom implementation of ControllerAdvice to handle ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found