module Amber::Schema::ControllerIntegration

Overview

Mixin for controllers to add schema validation

Direct including types

Defined in:

amber/schema/controller_integration_simple.cr

Macro Summary

Instance Method Summary

Macro Detail

macro auto_validate #

Macro for auto validation (simplified)


[View source]
macro response_schema(action, &block) #

Define a response schema for an action


[View source]
macro schema(action, &block) #

Define a request schema for an action


[View source]
macro validate_schema(action = nil, required = true) #

Before filter to validate requests


[View source]

Instance Method Detail

def render_validated(data : Hash(String, JSON::Any), status : Int32 = 200) #

Render with response validation (backward compatible)


[View source]
def respond_with(data : Hash(String, JSON::Any) | NamedTuple | Nil = nil, status : Int32 = 200, schema_name : String | Nil = nil) #

Helper method to respond with schema-validated data


[View source]
def respond_with_error(message : String, status : Int32 = 400, code : String | Nil = nil) #

Helper to create error response


[View source]
def respond_with_errors(errors : Array(Amber::Schema::Error), status : Int32 = 422) #

Helper to respond with validation errors


[View source]
def validate_request(schema_name : String | Nil = nil) : Amber::Schema::LegacyResult #

Validate request against schema


[View source]
def validate_response(data : Hash(String, JSON::Any), status : Int32 = 200, schema_name : String | Nil = nil) : Amber::Schema::LegacyResult #

Validate response against schema


[View source]
def validated_params : Hash(String, JSON::Any) | Nil #

Helper to access validated data (alias for request_data)


[View source]
def validation_failed? : Bool #

Helper to check if validation passed


[View source]