JSON Schema Validation in APIGEE

I'm working on a requirement to validate the incoming JSON Payload before i send it out to the backend , but unfortunately i didn't get any specific idea to work on the requirement . One way i saw is to define the JSON Schema and only define the mandatory fields in the Schema and set allow additional field to false . Is there is any policy in APIGEE which can run a JSON schema validation in the proxy . And if anyone has a JavaScript example please share it  . I have tried hasOwnProperty from JS but it didn't worked on the nested elements .

0 5 2,461
5 REPLIES 5

I assume you're on OPDK? For Hybrid & X there's a policy I think for JSON schema. 

We solved it by writing own java callout based on swagger core validator from atlassian

I'm not sure about the version though , can you provide me an example for java callout , so i can try implementing the same .

Not the version, but the flavor. Are you SaaS(X) or Hybrid Apigee user or your Apigee completely installed on your prem? 

 

For Apigee X  https://cloud.google.com/apigee/docs/api-platform/reference/policies/oas-validation-policy  > see this policy. @dchiesa1 can you please confirm that this policy works for Hybrid? 

 

If you are on-prem(OPDK) user, you might think of using java-callout. I cannot provide any code, this is commercial development. 

If OASValidataion policy is not an option, you can validate JSON schema using javascript library tv4 - https://github.com/geraintluff/tv4. We implemented using this library when OASValidation policy was not available on Apigee.

Hi,

 

As already mentioned OAS validation policy is an option. It may be preferred as it is out-of-the-box.

If that doesn't fit the bill then TV4 library is an option.

Points to consider

  1. Support for multiple content-type like (application/json, application/hal+json, application/x-www-form-urlencoded (encoding object not supported), multipart/form-data, text/plain, text/xml), Whereas OAS validation policy only support application/json to my knowledge (check on this)
  2. Custom OAS validation policy can give you the benefit to return the error response as per your custom defined format.
  3. Check all status /error codes are returned or supported using OAS Validation. Else go for custom TV4

thanks!