Skip to content

gravitee-io/gravitee-policy-json-validation

Repository files navigation

JSON validation policy

Gravitee.io License Releases CircleCI

Phase

onRequestContent onResponseContent

X

X

Description

You can use the json-validation policy to validate JSON payloads. This policy uses JSON Schema Validator. It returns 400 BAD REQUEST when request validation fails and 500 INTERNAL ERROR when response validation fails, with a custom error message body. It can inject processing report messages into request metrics for analytics.

Compatibility with APIM

Plugin version

APIM version

1.x

All supported versions

Configuration

Property Required Description Type Default

scope

X

Policy scope from where the policy is executed

Policy scope

REQUEST_CONTENT

errorMessage

X

Custom error message in JSON format. Spel is allowed.

string

{"error":"Bad request"}

schema

X

Json schema.

string

deepCheck

Validate descendant even if JSON parent container is invalid

boolean

false

validateUnchecked

Unchecked validation means that conditions which would normally cause the processing to stop with an exception are instead inserted into the resulting report. Warning: this means that anomalous events like an unresolvable JSON Reference, or an invalid schema, are masked!.

boolean

false

straightRespondMode

Only for RESPONSE scope. Straight respond mode means that responses failed to validate still will be sent to user without replacement. Validation failures messages are still being written to the metrics for further inspection.

boolean

false

Errors

HTTP status code

Code Message

400(Request scope)

500(Response scope)

Sent in the following cases:

* Invalid payload

* Invalid JSON schema

* Invalid error message JSON format

Errors

You can use the response template feature to override the default response provided by the policy. These templates must be defined at the API level (see the API Console Response Templates option in the API Proxy menu).

The policy sends the following error keys:

Key Parameters

JSON_INVALID_PAYLOAD

-

JSON_INVALID_FORMAT

-

JSON_INVALID_RESPONSE_PAYLOAD

-

JSON_INVALID_RESPONSE_FORMAT

-