Skip to main content

Module oas_validator

Module oas_validator 

Source
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 spec is an inline OpenAPI JSON object. APISIX’s spec (a JSON string) and spec_url (remote fetch) forms, a YAML loader, and secret-reference indirection are out of scope.
  • Faithful subset. Validated: presence of required query/header parameters, and the application/json requestBody schema. Local $refs (#/components/...) are resolved by embedding components into the compiled schema root. Not covered: response validation, parameter type/format coercion and schema validation, oneOf/anyOf operation selection, cookie parameters, and $refs to external documents.
  • APISIX’s skip_* toggles, verbose_errors, and reject_if_not_match are not modelled; a matched operation is always validated and violations are always rejected with rejected_code.

Structs§

CompiledOp 🔒
A compiled OpenAPI operation: everything needed to match a request and validate it, precomputed at config load.
OasValidatorPlugin
Validates requests against a compiled OpenAPI 3 spec.

Enums§

Segment 🔒
One segment of a templated OpenAPI path.

Constants§

HTTP_METHODS 🔒

Functions§

collect_required_params 🔒
Gathers required parameters (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/json requestBody schema for an operation, if present, embedding the spec’s components so 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.