1
votes

When using "Validate JSON Schema" element in Mulesoft, if more than one validation error occurs, following message is put into #[exception].

org.mule.api.MessagingException: Json content is not compliant with schema
com.github.fge.jsonschema.core.report.ListProcessingReport: failure
--- BEGIN MESSAGES ---
error: string "blah" is too long (length: 4, maximum allowed: 3)
    level: "error"
    schema: {"loadingURI":"file:/...}
    instance: {"pointer":"/blah_blah_code"}
    domain: "validation"
    keyword: "maxLength"
    value: "blah"
    found: 4
    maxLength: 3
error: string "USDe" is too long (length: 4, maximum allowed: 3)
    level: "error"
    schema: {"loadingURI":"file:/..."}
    instance: {"pointer":"/blah_code"}
    domain: "validation"
    keyword: "maxLength"
    value: "USDe"
    found: 4
    maxLength: 3
---  END MESSAGES  ---

Is there anyway to extract individual errors?

1

1 Answers

0
votes

You can use when condition inside catch-exception-strategy and set payload accordingly for each element

Below example for blah element

<when expression="#[exception.causedBy(org.mule.api.MessagingException)&amp;&amp; exception.cause.message.contains('schema') &amp;&amp; exception.cause.message.contains('blah')]">
  <set-payload value="include element specification here" doc:name="Json schema validation error"/>
</when>