I'm using Mule 4 and Anypoint Studio 7.
I'm defining and API with a common response structure because I want to use it with all examples I have, but is not working fine.
Example of two possible responses with the common structure:
Response with Employee Data:
{
"pagination": { "firstPage": 1, "numRows": 10 },
"data": { "employeeId": 1, "employeeName": "Alex" },
"success": true
}
Response with Employee Task:
{
"pagination": { "firstPage": 1, "numRows": 10 },
"data": { "employeeId": 1, "employeeTask": "Clean the appartment" },
"success": true
}
I'm trying to define the response structure with a trait:
responseMessage:
responses:
200:
body:
application/json:
example: |
{ "pagination": {"firstPage": 1, "numRows": 10}, "data": <<exampleName>>, "succes": true }
And finally, define the method:
/employees:
get:
type:
exampleReference1: |
{"SongID":1,"SongName":"London Dreams","Singer":"David"}
is: [responseMessage: { typeName: exampleReference1 }]
I'm getting "null" in "data" when I try "mock" service:
"pagination": {
"firstPage": 1,
"numRows": 10
},
"data": null,
"succes": true
}
You cannot use "
<<reference>>" inside a file because RAML treats everything as a String.Take a look here and modify the code according to your use case.
https://raml.org/developers/raml-200-tutorial#parameters