I'm going to hard code some data using x-mediation-script. Where as I want to use $ref which will be called in setPayloadjson. Is this possible can we do it? need suggestion with any of the sample
"x-mediation-script": "mc.setProperty('CONTENT_TYPE', 'application/json');mc.setPayloadJSON('$ref', '#/definitions/out');"
"definitions":{
"out":{
"type" : "object",
"required": ["NAME"],
"properties": {
"NAME2": {"type": "string"},
"NAME3": {"type": "string"},
"NAME3": {"type": "string"},
"NAME4": {"type": "string"},
}
}
}
It is not possible to access swagger content from the mediation script using $ref
due to,
As the solution, create a JS variable in the x-mediation-script and use it.
mc.setProperty('CONTENT_TYPE', 'application/json'); // Set the content type of the payload to the message context
var town = mc.getProperty('uri.var.town'); // Get the path parameter 'town' and store in a variable
mc.setPayloadJSON('{ "Town" : "'+town+'"}'); // Set the new payload to the message context.