How to use "anyOf" in JSON schema validation which is using RAML and MULE API?

524 Views Asked by At

I need to implement schema validation for incoming JSON payload.

The below elements will be there in the JSON,

          "partyId": {
            "type": ["string","null"],
            "maxLength": 16,
            "required": false,
            "description": "Party ID"
          },
          "erpId": {
            "type": ["string","null"],
            "maxLength": 20,
            "required": false,
            "description": "ERP ID"
          }

Required validation : Any one element should be available in JSON, Else it should reject the request.

My project is using "$schema":"http://json-schema.org/draft-06/schema#"

Some follow up question?

  1. How to find which schema draft version using in my project (some schema json file there is no draft version in the top)?
  2. Which maven dependency is supporting this schema draft version ?
1

There are 1 best solutions below

0
On
  • the required keyword takes a list of property names, not a boolean. It should live at the same level as "type": "object" and "properties".

https://json-schema.org/understanding-json-schema/reference/object.html#required-properties

  • you can use anyOf to check for the availability of any of a multiple number of properties.

https://json-schema.org/understanding-json-schema/reference/conditionals.html