Expand description
The oas-validator node — validates the incoming request against an
OpenAPI 3 (OAS 3) specification before it reaches the upstream.
Port of APISIX’s oas-validator plugin. The OpenAPI document is supplied
inline as a JSON object in the node config; at config load every
operation’s requestBody JSON Schema is compiled and its required
parameters are indexed, so a malformed spec or an uncompilable schema fails
policy compilation, not a live request.
At request time the plugin matches the request’s method + path (with
OpenAPI path templating, e.g. /users/{id} matches /users/123) against
the spec. When an operation matches it validates required query/header
parameters and the JSON request body against the operation’s schema; on any
violation the request is rejected through the error port. When no
operation matches, the request passes through untouched (matching APISIX:
it is not the validator’s job to 404).
§Deviations from APISIX / scope
- Inline-JSON spec only. The
specis an inline OpenAPI JSON object. APISIX’sspec(a JSON string) andspec_url(remote fetch) forms, a YAML loader, and secret-reference indirection are out of scope. - Faithful subset. Validated: presence of
requiredquery/header parameters, and theapplication/jsonrequestBodyschema. Local$refs (#/components/...) are resolved by embeddingcomponentsinto the compiled schema root. Not covered: response validation, parameter type/format coercion and schema validation,oneOf/anyOfoperation selection, cookie parameters, and$refs to external documents. - APISIX’s
skip_*toggles,verbose_errors, andreject_if_not_matchare not modelled; a matched operation is always validated and violations are always rejected withrejected_code.
Structs§
- Compiled
Op 🔒 - A compiled OpenAPI operation: everything needed to match a request and validate it, precomputed at config load.
- OasValidator
Plugin - Validates requests against a compiled OpenAPI 3 spec.
Enums§
- Segment 🔒
- One segment of a templated OpenAPI path.
Constants§
Functions§
- collect_
required_ 🔒params - Gathers
requiredparameters (query + header) for an operation, merging path-item-level and operation-level parameter lists and resolving local$refs. Returns(required_query, required_headers_lowercased). - compile_
body_ 🔒schema - Compiles the
application/jsonrequestBody schema for an operation, if present, embedding the spec’scomponentsso local$refs resolve. - parse_
template 🔒 - Splits an OpenAPI path template into segments.
- path_
matches 🔒 - Returns true if a request path matches this operation’s segment template.
- resolve_
ref 🔒 - Resolves a local JSON pointer
$ref(#/a/b/c) against the root document.