#DTO with array with brackets

7 messages · Page 1 of 1 (latest)

neon marlin
#

Today I upgraded the codebase to Nest v11 and since I have this issue with a DTO:

export class TestDto {
  @IsEthereumAddress({ each: true })
  addresses: Address[];
}

I query the endpoint like this:
https://test.com/?addresses[]=0x0&addresses[]=0x1
The above used to work with Nest 10 and now fails with a Bad Request.
Note that the project is using Express.

{
    "message": [
        "each value in addresses must be an Ethereum address"
    ],
    "error": "Bad Request",
    "statusCode": 400
}

The requests succeeds if I remove the brackets from the URL:
https://test.com/?addresses=0x0&addresses=0x1

But I still need it to work with the brackets.
I didnt find anything in the documentation regarding a change like this. Would love a pointer to where I should look to allow the brackets again as it's a breaking change in the API. 🙏

fading abyss
#

That's most likely got to do with the underlying query parser. Are you using express as the HTTP engine?

neon marlin
#

Yes!

#

From the bootstrap function:

  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.useBodyParser("json", { limit: "50mb" });
  app.useBodyParser("urlencoded", { limit: "50mb" });
  app.enableShutdownHooks();
  app.enableCors({
    credentials: true,
    origin: true,
  });
  app.useGlobalPipes(new ValidationPipe({ transform: true }));
fading abyss
#

I believe you need to set the query parser to extended. Let me recall how to do that

#

app.set('query parser', 'extended')

neon marlin
#

Thanks for the quick answer will try it when I’m back! 🫶