Skip to content

v0.5.0: full schema validation, richer annotations and schema_for - #6

Merged
erayjsx merged 3 commits into
mainfrom
claude/project-thread-0tyjr6
Oct 14, 2026
Merged

erayjsx merged 3 commits into
mainfrom
claude/project-thread-0tyjr6

Conversation

@erayjsx

@erayjsx erayjsx commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Requested by Eray · project thread

Before: request validation only checked types and required fields. Constraints like enum, minLength, pattern or oneOf were documented but never enforced. Multipart routes got a 400 on every request. parameters and security in @[OpenAPI] were silently dropped. schema_for(User) did not compile at the top level, even though that is how the README showed it.

After: JSON bodies are validated against the full schema, and every error is reported with a JSON Pointer. Non-JSON bodies pass through untouched. Oversized bodies get 413 and a wrong Content-Type gets 415. The annotation supports parameters, security, "default" responses and schema expressions. Path parameters are documented automatically, and schema_for maps real Crystal types, including nested types, enums, collections and unions.

How

  • validator.cr is rewritten around errors_for(json, schema), which collects ValidationError(pointer, message) values. The response body keeps error and message (the first error) and adds an errors array.
  • Schema#type is now nilable with an effective_type. Pure oneOf/anyOf/allOf, $ref and enum schemas no longer default to object, and existing schemas still emit "type": "object". New keywords: exclusiveMinimum/exclusiveMaximum, multipleOf, minItems/maxItems/uniqueItems, readOnly/writeOnly, title, deprecated.
  • Route macros use the block's own argument name and fall back to plain Kemal routing for non-literal paths. They give a clear compile error when the block is missing.
  • schema_for is now a generic method (forall T), because instance_vars is not available at the top level. Nested types are inlined up to max_depth (4 by default), so recursive types are safe.
  • The spec cache is invalidated on register*, ReDoc is pinned to 2.5.4, the docs handler only answers GET/HEAD, and the UI title follows setup(title:).
  • Added a CI workflow (specs on Crystal 1.19.1 and latest, plus a format check and an example build), a CHANGELOG, and README updates. Version bumped to 0.5.0.

Breaking changes for 0.x: Schema#type and Response#status_code are now nilable.

The second commit is crystal tool format only. Run locally: 84 specs pass on Crystal 1.19.1 and 1.22.0 with Kemal 1.14.0, and example/app.cr plus the README snippets compile.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Aj3mC5LttRzqomzHWPj4M


Generated by Claude Code

Validator
- Enforce enum, length, pattern, numeric bounds, array size/uniqueness,
  additionalProperties and oneOf/anyOf/allOf; report every error with a
  JSON Pointer
- Only parse JSON media types, return 415 for non-JSON Content-Type and
  413 above Kemal's max_request_body_size
- Validate annotated routes even when setup is never called

Annotations and spec
- Support parameters, security, "default"/range responses and schema
  expressions in request_body
- Document undocumented path parameters (:id, *glob) automatically
- Accept route blocks with any argument name

schema_for
- Make it a generic method so it works at the top level
- Map Int64/UInt/Float32, Time, UUID, enums, typed collections, nested
  serializable types, unions and JSON::Any; fields with defaults are optional

Also: refresh the spec cache on registration, pin ReDoc, serve docs only
on GET/HEAD, add CI, CHANGELOG and README updates.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Aj3mC5LttRzqomzHWPj4M
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Aj3mC5LttRzqomzHWPj4M
@erayjsx erayjsx self-assigned this Oct 14, 2026
@erayjsx
erayjsx marked this pull request as ready for review October 14, 2026 17:14
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Aj3mC5LttRzqomzHWPj4M
@erayjsx
erayjsx merged commit e6acc1d into main Oct 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants