#is there a way to validate object but not nested)?

10 messages · Page 1 of 1 (latest)

graceful creek
#

Hi, a little unusual question probably, sorry if that would be bad approach)
I have data from client like

{
"data":"somedata",
"another":"data"
}

how to validate body like this

key is string and key-name is any
value is any

using class-validator

exotic wave
#

Can you elaborate? I have no idea what you're trying to say..

#

but dynamic keys are impossible to validate using a class

graceful creek
#

I just need to validate request that could have dynamic keys (keys are just a random names and that could be many of them) and values that could be any
if that's impossible using class are there any other approaches?

exotic wave
#

Json schema (using AJV) for example, but, you'll need a custom validation pipe for that

#

But if you can accept random keys with any value, then what is there to validate?

graceful creek
#

just that object is not empty)

#

I need at least one key:value

#

and I should not pass for example
{"asdf"}

exotic wave
#

It might be easiest to just check that condition in the controller rather than coming up with an elaborate solution