Apigee json schema validation

Hello 

 

Currently, we are searching ways to refine and  optimize our APIs. One of what we are looking for is to make json schema validation for queries, URIs for related APIs.

Is there any suggestions about how to implement this idea as l’m not able yet to find a good solution to go with it.

all answers are appreciated 

thanks in advance, 

Fasaiel

Solved Solved
0 3 837
1 ACCEPTED SOLUTION

OpenAPI Spec often includes JSON Schema. IF you are using OpenAPI Spec (fka Swagger spec) , then you can use the OASValidation policy that is builtin to APigee to get the implicit JSON schema validation.

If you don't have an OpenAPI Spec and you just want to validate a JSON payload against a schema, you need to use a Java callout or JS callout to do so.  Here's an example: https://github.com/DinoChiesa/ApigeeEdge-Java-Validate-JSON-Schema

I suggest you search the Apigee community archives for more info and context. I believe this question has been discussed before.

View solution in original post

3 REPLIES 3

OpenAPI Spec often includes JSON Schema. IF you are using OpenAPI Spec (fka Swagger spec) , then you can use the OASValidation policy that is builtin to APigee to get the implicit JSON schema validation.

If you don't have an OpenAPI Spec and you just want to validate a JSON payload against a schema, you need to use a Java callout or JS callout to do so.  Here's an example: https://github.com/DinoChiesa/ApigeeEdge-Java-Validate-JSON-Schema

I suggest you search the Apigee community archives for more info and context. I believe this question has been discussed before.

It’s seems like what I’m looking for . I will do investigation on it then I will write here my updates .

one thing that I’ve found but I’m not sure about how I can use it. What about the property set policy. Can I use it for validating queries parameters that common in all relevant API’s? Hopefully its clear to you 


@Fasaiel wrote:

What about the property set policy.


There is a thing called propertysets in Apigee, but it is not a policy.  I think we call them "resources".  Propertyset is a type of resource within a proxy. 

Propertysets are a good way to pass a set of key/value pairs to a proxy.  You can define settings like URLs or encoded keys, or any other values, and the propertyset mechanism will just load all of those values into pre-defined context variables. Your proxy can then just refer to those variables when handling requests. So it's pretty handy. 

I don't see how you could use propertysets for validating that there are some common queryparams. 

I guess you could have some boilerplate JavaScript which gets used by "every proxy", and it would refer to the set of required query params.  You could follow a convention in which every proxy must have a propertyset that defines the list of required queryparams for that particular proxy.  And then the JS would just do the validation. 

This would validate only the presence of queryparams; it wouldn't validate the JSON schema of any payloads.

And you'd have to build the logic to validate the qparams yourself. This might be a small job, but I wanted to point it out.