# validate/v1 — Format validation

LLMs generate plausible-looking JSON and regex output without guaranteeing
it actually conforms — this module gives a deterministic answer instead.
High value for agent workflows that need to validate structured output
before acting on it.

### `POST /v1/validate/regex`

Tests `input` against `pattern`. Go's `regexp` package is **RE2, not
PCRE** — no backreferences, no lookahead/lookbehind. Inline flags like
`(?i)` (case-insensitive) are supported directly in the pattern string, so
there's no separate flags field.

**Request**

```json
{ "pattern": "^(\\w+)@(\\w+)$", "input": "alice@wonderland" }
```

**Response — match**

```json
{ "matches": true, "match": "alice@wonderland", "groups": ["alice", "wonderland"] }
```

`groups` are the captured subgroups (empty array if the pattern has none).

**Response — no match**

```json
{ "matches": false }
```

**Error response** (invalid pattern)

```json
{ "error": "invalid regex pattern: error parsing regexp: missing closing ]: `[abc`" }
```

### `POST /v1/validate/email`

Checks `value` is a single, bare RFC 5322 email address — **syntax only**,
not a deliverability or domain-existence check. `user@localhost` is valid
(RFC 5322 doesn't require a TLD). `"John Doe <john@example.com>"` is
rejected — this validates a bare address, not a full address-header value.

```bash
curl -s -X POST https://apished.com/v1/validate/email \
  -H 'Content-Type: application/json' \
  -d '{"value": "user@example.com"}'
# {"valid":true}
```

### `POST /v1/validate/url`

Checks `value` is a well-formed **absolute** URL (has both a scheme and a
host) — syntax only, not a reachability check. A relative path like
`/foo/bar` is rejected (no scheme); `https://` alone is rejected (no
host).

```bash
curl -s -X POST https://apished.com/v1/validate/url \
  -H 'Content-Type: application/json' \
  -d '{"value": "https://example.com/path?q=1"}'
# {"valid":true}
```

### `POST /v1/validate/jsonschema`

Validates `document` against `schema` (JSON Schema draft-07 or 2020-12,
via `github.com/google/jsonschema-go`).

**Request**

```json
{
  "schema": {
    "type": "object",
    "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } },
    "required": ["name", "age"]
  },
  "document": { "name": "Al" }
}
```

**Response — invalid**

```json
{ "valid": false, "reason": "validating root: required: missing properties: [\"age\"]" }
```

The library reports **one specific violation per call**, not every
violation aggregated — fix the reported one and validate again to find the
next, same as a compiler reporting one error at a time.

**Error response** (malformed schema or document JSON — not a validation
failure, a request problem)

```json
{ "error": "invalid schema: expected a JSON object, got string" }
```

## Files

- `validatemodule.go` — module wiring (routes, HTTP handlers)
- `validate.go` — pure validation logic
- `validate_test.go` — test vectors per validator
