Validating Properties

What is Validating Properties?

Sometimes it is required to validate the value of Properties in the Property Store in order to make sure they comply to a given set of rules.

For Properties of type application/json you can use the JSON Schema specification for validating.

For more details see here: https://logabit.atlassian.net/wiki/spaces/PA/pages/2545090620 .

PIPEFORCE provides built-in toolings for storage, resolving and validation using JSON Schemas.

Store a JSON Schema in the Property Store

By default, a JSON schema which describes a JSON object (= document) within PIPEORCE is placed in a property with content type application/json in the property store using this property path:

global/app/<APP>/object/<NAME>/v1/schema

Where <APP> is the name of the app, the object belongs to. <NAME> is the name of the object. In the example of a person which is part of the app myappp, you could use this path to access the object schema in a unique way from within the overall PIPEFORCE instance:

global/app/myapp/object/person/v1/schema

Validate a JSON document

In order to validate whether a given JSON document complies with such a given JSON schema, you can use the command json.validate. This command will by default check whether a given document is a valid JSON document (= syntax validation). Additionally, a JSON Schema can be defined which should be loaded and used as based for schema validation (= structural validation).

This example will validate a JSON given in the body using the JSON schema from above which is now stored in the property store:

body: { "firstName": "Sam", "lastName": "Meyer", "age": 48, "gender": "male" } pipeline: - json.validate: schema: $uri:global/app/myapp/object/person/v1/schema

In case the given JSON document is valid and complies with the JSON schema rules, OK is returned:

Let’s change the value of field age now to a string value (in line 4) instead and validate again.

This will return a validation error like this:

Â