Validate Query string and params using ajv in node js

116 Views Asked by At

Is there a way we can validate query string and prams in the url using AJV, i know we can validate JSON.

So consider if i have a url like http://localhost:300/messgae/:messageId how can i validate this param messageId?

Im using AJV version 8.12.0

I tried the schema something like this

const GetConversationOutput = {
    type: "object",
    properties: {
        params: {
            type: "object",
            properties: {
                messageId: {
                    type: "string",
                    minLength: 1,
                    maxLength: 24
                }
            },
            required: ["messageId"],
            additionalProperties: false
        }
        
    }
}

But its not working. Thanks.

0

There are 0 best solutions below