Skip to content

v0.6.0: parameter validation, registries, spec export and repo tooling - #7

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

erayjsx merged 4 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

What does this change?

Before: only request bodies were validated, so ?page=abc reached the route. There was no way to get the spec without running the server. Every operation shared one global registry, nested types were always inlined, and the repo had no linter or contribution docs.

After:

  • Parameters: query, path, header and cookie values are converted to their schema type and validated, and failures return 422 with an in field.
  • Spec export: KEMAL_OPENAPI_EXPORT=openapi.json crystal run src/app.cr writes the spec and exits.
  • Registries: Kemal::OpenAPI::Registry lets one app serve several independent API descriptions.
  • operationId: generated automatically, e.g. getUsersById.
  • Shared types: register_schema_for(User) registers nested types as $ref components, recursive types included.
  • Response checks: validate_responses: true logs routes whose JSON responses don't match their documentation.
  • Tooling: ameba, Dependabot, issue and PR templates, CONTRIBUTING.md and SECURITY.md.

How

  • Registry holds operations, schemas and security schemes, plus a version counter that the handler's spec cache follows. OPERATIONS, SCHEMAS and the other constants are now the default registry's collections, so existing code keeps working.
  • Validator is now an instance bound to a registry, and the class methods take an optional registry:. Parameter values come from query_params.fetch_all, route_lookup.params, headers and cookies, and are converted to the schema type before validation.
  • Route macros capture the block's value through a yielding Kemal::OpenAPI.run_route rather than a proc, so next and Kemal's halt keep working (there is a spec for this). They also accept _ as the block argument, which ameba's autofix turned up.
  • ws and QUERY stay undocumented because OpenAPI 3.1 cannot describe them. The README says so.

How was it tested?

24 new specs, 108 total. Locally, crystal spec, crystal tool format --check, bin/ameba, the example/app.cr build and a compile of every README snippet all pass on Crystal 1.19.1 and 1.22.0 with Kemal 1.14.0. I also checked KEMAL_OPENAPI_EXPORT by hand: it writes the file and exits 0, and without it the app starts normally.

Checklist

  • crystal spec passes
  • crystal tool format --check and bin/ameba pass
  • README and CHANGELOG are updated for user-facing changes

🤖 Generated with Claude Code

https://claude.ai/code/session_018Aj3mC5LttRzqomzHWPj4M


Generated by Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Aj3mC5LttRzqomzHWPj4M
…(v0.6.0)

- Validate query, path, header and cookie parameters, coercing string
  values to the schema type
- Add Kemal::OpenAPI::Registry so one app can serve several API
  descriptions; the legacy constants point at the default registry
- Export the spec with KEMAL_OPENAPI_EXPORT, write_spec or spec_json
- Generate operationIds for operations that lack one
- register_schema_for registers nested types as $ref components
- Optional response validation that logs schema mismatches
- Accept `_` as a route block argument
- Apply ameba fixes; add ameba as a development dependency

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
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 marked this pull request as ready for review October 14, 2026 17:48
@erayjsx
erayjsx merged commit 392db71 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