module
Amber::Schema::ControllerIntegration
Overview
Mixin for controllers to add schema validation
Direct including types
Defined in:
amber/schema/controller_integration_simple.crMacro Summary
-
auto_validate
Macro for auto validation (simplified)
-
response_schema(action, &block)
Define a response schema for an action
-
schema(action, &block)
Define a request schema for an action
-
validate_schema(action = nil, required = true)
Before filter to validate requests
Instance Method Summary
-
#render_validated(data : Hash(String, JSON::Any), status : Int32 = 200)
Render with response validation (backward compatible)
-
#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
-
#respond_with_error(message : String, status : Int32 = 400, code : String | Nil = nil)
Helper to create error response
-
#respond_with_errors(errors : Array(Amber::Schema::Error), status : Int32 = 422)
Helper to respond with validation errors
-
#validate_request(schema_name : String | Nil = nil) : Amber::Schema::LegacyResult
Validate request against schema
-
#validate_response(data : Hash(String, JSON::Any), status : Int32 = 200, schema_name : String | Nil = nil) : Amber::Schema::LegacyResult
Validate response against schema
-
#validated_params : Hash(String, JSON::Any) | Nil
Helper to access validated data (alias for request_data)
-
#validation_failed? : Bool
Helper to check if validation passed
Macro Detail
Before filter to validate requests
Instance Method Detail
Render with response validation (backward compatible)
Helper method to respond with schema-validated data
Helper to create error response
Helper to respond with validation errors
Validate request against schema
Validate response against schema
Helper to access validated data (alias for request_data)