OapiCodemode.Proxy.Validator (oapi_codemode v0.3.1)

Copy Markdown View Source

Validates an intercepted request against the operation's dereferenced schema.

Deliberately shallow: types, required, enums — recursively through objects and arrays, but no oneOf/anyOf/allOf arbitration, no pattern/format checks (v1 scope). Error messages quote the violated schema fragment: the spec is the documentation the model just read, so errors grounded in it are actionable.

Coverage (v1 decision): query, body, and path parameters are validated. Header and cookie parameters are NOT validated — only path bindings come from a source (the matcher) the library controls closely enough to check cheaply; headers/cookies are left to the upstream API to reject.

Also deliberate: unknown/undeclared query parameters and additionalProperties on objects are never rejected. Validation here is a guardrail that catches the model's mistakes against the spec it just read — not a firewall. Anything not covered by the schema passes through unchanged.

Summary

Functions

validate(op, request \\ %{})

@spec validate(
  OapiCodemode.Operation.t(),
  %{
    optional(:query) => map(),
    optional(:body) => term(),
    optional(:path_params) => map()
  }
) :: :ok | {:error, String.t()}