Infer input schema
rego_infer_input_schemaStatically analyzes Rego policies to infer a JSON Schema of every input field they read, helping generate test inputs and validate policies before running OPA.
Instructions
Statically analyse one or more Rego policies and return a JSON Schema (draft-07) object describing every input.* field the policies read. It follows the ways a policy reads input: loop variables (some c in input.containers then c.image), rules whose value is an input path (pod_spec := input.request.object.spec), function parameters (trusted(c)) and object.get keys. A key the policy computes is left open, and a scalar type is set only where a comparison with a literal, an is_* check or a string built-in shows it. Uses opa parse -- no running OPA server required. A starting point for test inputs and for a schema to give rego_check_schema; review it first, since types the policy never shows are left out. Accepts inline source, individual files, or directories (walked recursively for *.rego files).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | No | Policy files or directories to analyse. Each must be inside an allowed root (OPA_MCP_ALLOWED_PATHS). Directories are walked recursively for *.rego files. | |
| source | No | Inline Rego source to analyse. Mutually exclusive with paths. | |
| v0Compatible | No | Read the policy as Rego v0 (`--v0-compatible`), the syntax OPA used before 1.0: rules without `if`, partial sets as `deny[msg] { ... }`. Needed for a policy that has not been migrated, which OPA 1.x otherwise refuses to load. Where the tool also takes a query, the query is read as v0 too, with the future keywords imported so `in`, `every` and `some x in` still work in it. |