Document updated on Oct 25, 2022
The response schema validator plugin adds a schema validation before the gateway returns the response to the end-user or before it’s merged in the endpoint with the rest of the backends.
Before returning the response, you can define the minimum response fields and their characteristics through JSON schema syntax (drafts 04, 06, and 07 supported).
To validate requests using JSON schema see validation/json-schema
instead.
You can use this plugin in conjunction with other components and perform validations, and you can insert it either in the endpoint section or the backend section. For instance, it can be part of a sequential proxy call and decide that the response does not have enough data to move forward and cancel the cascading connection.
The configuration of the plugin is as follows:
{
"extra_config": {
"plugin/req-resp-modifier": {
"name": [
"response-schema-validator"
],
"response-schema-validator": {
"schema": {},
"error": {
"body": "",
"status": 500
}
}
}
}
}
| In case the validation fails, the error definition containing body and status. Example: {"body":"We couldn't process you request, try again later.","status":401}
| ||||
| Write your JSON schema directly in this field, with any number of fields or validations you need. |
For instance, the schema example below makes sure that the response from the backend/endpoint merge contains:
{
"user": {
"username": "john",
"user_id": 178989,
"status": "registered"
}
}
The configuration:
{
"extra_config": {
"plugin/req-resp-modifier": {
"name": [
"response-schema-validator"
],
"response-schema-validator": {
"schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"user_id": {
"type": "number"
},
"status": {
"type": "string",
"enum": ["registered", "banned"]
}
},
"required": [
"username",
"user_id"
]
}
},
"required": [
"user"
]
},
"error": {
"body": "We couldn't process you request, try again later.",
"status": 401
}
}
}
}
}
The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.