I am defining a new API and in Design centre have defined RAML endpoint as :
/employees:
get:
type:{
ResourceTypes.getInstance: {
typeName: object,
exampleInstance: !include examples/get-employee-response.json
}
}
get-employee-response.json
is a simple json :
{
"empId" : 100,
"empName : "John",
...
...
}
Now what I am confused is that I know the input can get validated by API Kit router However to validate response - document here states that we will need to use JSON Schema
However I was unable to understand the last few sentences:
If your response schema is encapsulated in a DataType (as per RAML 1.0), unfortunately this cannot be utilised for validation purposes and you will need to maintain a separate JSON schema for that.
So really can someone explain how do we go about it ? If there is an example that would greatly help ! Thanks !
The sentence means that the JSON Schema Validator (for Mule 3.x) or the JSON Module Validator (for Mule 4.x) are used to validate a JSON document against a JSON Schema. They can not use the type description from the RAML definition of your API. You will need to obtain or create a JSON schema to use them.
I'm not sure why do you need to validate the output. If your API implementation may not generate a valid output that should be identified through testing and fixed. If the validation fails, what is the expected outcome? I suspect it would be more understandable if you are receiving the JSON output from a backend and want to validate it before returning.
Note that the article that you linked to is for Mule 3.x.