Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpQuery validator expression in first argument leaks to other parameters #614

Open
marcj opened this issue Sep 25, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@marcj
Copy link
Member

marcj commented Sep 25, 2024

test('query validator withing HttpQuery', async () => {
    class Controller {
        @http.GET('do')
        async do(
            a: HttpQuery<string & MinLength<8>>,
            b: HttpQuery<string>,
        ) {
            return { valid: true };
        }
    }

    const httpKernel = createHttpKernel([Controller]);
    expect((await httpKernel.request(HttpRequest.GET('/do').query('a=aaaaaaaa&b=bbbb'))).json).toMatchObject({
        valid: true
    });
});

this should work, but fails since b parameter also gets the MinLength<8> validator attached. Error:

message": "Validation error:
b(minLength): Min length is 8 caused by value "bbbb"
@marcj marcj added the bug Something isn't working label Sep 25, 2024
@marcj
Copy link
Member Author

marcj commented Sep 25, 2024

fix/workaround is putting the validator outside of HttpQuery. likely related to type caches

        @http.GET('do')
        async do(
            a: HttpQuery<string> & MinLength<8>,
            b: HttpQuery<string>,
        ) {
            return { valid: true };
        }

marcj added a commit that referenced this issue Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant