Zodra

Configuration

Configure Zodra output paths, key formats, validation, and OpenAPI settings

Configuration

Configure Zodra in an initializer:

config/initializers/zodra.rb
Zodra.configure do |config|
  config.output_path = "app/javascript/types"
  config.key_format = :camel
  config.zod_import = "zod"
  config.strict_params = true

  # OpenAPI / Swagger UI
  config.openapi_title = "My API"
  config.openapi_version = "1.0.0"
  config.openapi_description = "API documentation"
end

Options

output_path

Directory where generated TypeScript files are written.

Default: "app/javascript/types"

config.output_path = "frontend/src/zodra"

key_format

Controls how Ruby snake_case keys are transformed in generated output and how incoming request params are normalized at runtime.

Default: :camel

ValueRuby keyGenerated keyIncoming params
:camelcreated_atcreatedAtcamelCasesnake_case
:snakecreated_atcreated_atcamelCasesnake_case
:keepcreated_atcreated_atNo normalization

When key_format is :camel or :snake, Zodra automatically converts incoming camelCase request params to snake_case before validation. This means the frontend sends camelCase keys (matching the generated schemas), and the controller receives snake_case keys (matching Ruby conventions). With :keep, params are passed through as-is.

config.key_format = :snake

zod_import

The import path for Zod in generated schemas.

Default: "zod"

# Use a custom Zod wrapper
config.zod_import = "@/lib/zod"

strict_params

When true, unknown keys in request params cause a validation error. When false, unknown keys are silently ignored.

Default: true

config.strict_params = false

openapi_title

Title displayed in the Swagger UI header and OpenAPI info.title.

Default: "API"

config.openapi_title = "My E-Commerce API"

openapi_version

API version in the OpenAPI info.version field.

Default: "1.0.0"

config.openapi_version = "2.0.0"

openapi_description

Optional description below the title in Swagger UI.

Default: nil

config.openapi_description = "Order management API"

On this page