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

Array does not work with HttpBody #414

Open
colorcube opened this issue Feb 21, 2023 · 2 comments
Open

Array does not work with HttpBody #414

colorcube opened this issue Feb 21, 2023 · 2 comments

Comments

@colorcube
Copy link
Contributor

@http.POST('')
async stuff(body: HttpBody<string[]>) {

Debugger shows: This route has no body defined.

Sending data results in a Validation error:

{
    "message": "Validation error:\n(type): Not an array",
    "errors": [
        {
            "path": "",
            "code": "type",
            "message": "Not an array"
        }
    ]
}

If it's not intended to use arrays with HttpBody a remark in the docs might be good.

@marcj
Copy link
Member

marcj commented Feb 21, 2023

What's the request's body and header?

@colorcube
Copy link
Contributor Author

I stumbled across this problem again and found my own bugreport :-)

@http.POST('/example')
async example(exampleDtoList: HttpBody<ExampleDto[]>) {

HttpBody validation fails:

{
    "message": "Validation error:\n(type): Not an array",
    "errors": [
        {
            "path": "",
            "code": "type",
            "message": "Not an array"
        }
    ]
}

I checked and it is clearly a json array transported with
Content-Type: application/json

Workaround:

@http.POST('/example')
async example(request: HttpRequest) {
    const body = await request.readBodyText()
    const exampleDtoList = deserialize<ExampleDto[]>(JSON.parse(body));

version 1.0.1-alpha.97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants