Skip to content

The request-validation plugin is used to validate requests forwarded to upstream services in advance. This plugin utilizes the JSON Schema mechanism for data validation, capable of validating both the body and header data of requests.

Plugin Execution Phase: Authentication Phase
Plugin Execution Priority: 220

NameData TypeRequirementsDefault ValueDescription
header_schemaobjectOptional-Configuration for JSON Schema to validate request headers
body_schemaobjectOptional-Configuration for JSON Schema to validate request body
rejected_codenumberOptional403HTTP status code returned when the request is rejected
rejected_msgstringOptional-HTTP response body returned when the request is rejected
enable_swaggerboolOptionalfalseConfiguration to enable Swagger documentation validation
enable_oas3boolOptionalfalseConfiguration to enable OAS3 documentation validation

Validation rules for header and body are the same, below is an example using body.

body_schema:
type: object
required:
- enum_payload
properties:
enum_payload:
type: string
enum:
- "enum_string_1"
- "enum_string_2"
default: "enum_string_1"
body_schema:
type: object
required:
- boolean_payload
properties:
boolean_payload:
type: boolean
default: true

Number Range (Number or Integer) Validation

Section titled “Number Range (Number or Integer) Validation”
body_schema:
type: object
required:
- integer_payload
properties:
integer_payload:
type: integer
minimum: 1
maximum: 10
body_schema:
type: object
required:
- string_payload
properties:
string_payload:
type: string
minLength: 1
maxLength: 10
body_schema:
type: object
required:
- regex_payload
properties:
regex_payload:
type: string
minLength: 1
maxLength: 10
pattern: "^[a-zA-Z0-9_]+$"
body_schema:
type: object
required:
- array_payload
properties:
array_payload:
type: array
minItems: 1
items:
type: integer
minimum: 1
maximum: 10
uniqueItems: true
default: [1, 2, 3]
body_schema:
type: object
required:
- boolean_payload
- array_payload
- regex_payload
properties:
boolean_payload:
type: boolean
array_payload:
type: array
minItems: 1
items:
type: integer
minimum: 1
maximum: 10
uniqueItems: true
default: [1, 2, 3]
regex_payload:
type: string
minLength: 1
maxLength: 10
pattern: "^[a-zA-Z0-9_]+$"
body_schema:
type: object
required:
- boolean_payload
properties:
boolean_payload:
type: boolean
rejected_code: 403
rejected_msg: "Request rejected"