I wanted a dependency schema using mongodb loopback. My Post requests:
REQUEST TYPE 1
{
“url”: “google.com”
“type”: “redirect”
}
REQUEST TYPE 2
{
“url”: “yahoo.com”
“type”: “anchor”
}
My model function looks like
@property({
type: 'string',
required: true,
})
type: string;
@property({
type: 'string',
required: true,
jsonSchema: {
maxLength: 2000,
pattern: '^[\\]*$', //using some regex
},
})
url: string;
My problem is I want this url pattern to be checked only if type in the payload is redirect. I read about json schema dependencies. But it is not working. Nor giving any error. I am trying something like:
@property({
type: 'string',
required: true,
jsonSchema: {
maxLength: 2000,
"dependencies": {
if(type == “redirect){
pattern: '^[\\]*$', //using some regex }
}
},
})
url: string;