Request Validation
Plenum validates incoming request bodies against the schemas defined in your OpenAPI spec. Attach the built-in internal:validate-request interceptor to an operation and it automatically uses the schema from the spec’s requestBody — no need to duplicate it.
Working example: see
examples/validation/
Configuration
Section titled “Configuration”Attach the interceptor to any operation that has a requestBody schema:
actions: - target: "$.paths['/items'].post" update: x-plenum-interceptor: - module: "internal:validate-request" hook: "on_request" function: "validateRequest"The interceptor reads the schema from the spec’s requestBody.content.application/json.schema automatically, including $ref references to components/schemas.
Behaviour
Section titled “Behaviour”# Valid request — proxied to backend$ curl -X POST http://localhost:6188/items \ -H "Content-Type: application/json" \ -d '{"name": "Widget", "quantity": 5}'# => 201
# Missing required field — rejected by gateway$ curl -X POST http://localhost:6188/items \ -H "Content-Type: application/json" \ -d '{"name": "Widget"}'# => 400 {"type":"request-validation-error","title":"Request Validation Failed",...}
# Wrong type — rejected by gateway$ curl -X POST http://localhost:6188/items \ -H "Content-Type: application/json" \ -d '{"name": "Widget", "quantity": "five"}'# => 400What gets validated
Section titled “What gets validated”The interceptor validates against the JSON Schema from the spec, including:
- Required fields
- Type checking (string, integer, boolean, etc.)
- Additional constraints (enum, pattern, min/max, etc.)
$refreferences to shared schemas incomponents/schemas
Overriding the schema
Section titled “Overriding the schema”To validate against a different schema than the one in the spec, provide an explicit options.schema:
x-plenum-interceptor: - module: "internal:validate-request" hook: "on_request" function: "validateRequest" options: schema: type: object properties: name: type: string quantity: type: integer required: - name - quantityWhen options.schema is provided, it takes precedence over the spec schema.
For response validation, see Response Validation.