Skip to content

Schema API Reference ​

Schema-based validation for .env configurations.

Schema ​

Schema.init ​

zig
pub fn init(fields: []const FieldDef) Schema

Create a new schema from field definitions.

Schema.validate ​

zig
pub fn validate(self: Schema, allocator: std.mem.Allocator, vars: *const std.StringHashMap([]const u8)) ![]ValidationError

Validate a set of key-value pairs against this schema. Returns an owned slice; free it with allocator.free when done.

FieldDef ​

zig
pub const FieldDef = struct {
    key: []const u8,
    required: bool = true,
    defaultValue: ?[]const u8 = null,
    defaultFn: ?DefaultFn = null,
    validatorsList: []const ValidatorFn = &.{},
    description: ?[]const u8 = null,
};
FieldTypeDefaultDescription
key[]const u8—The key name
requiredbooltrueWhether the field is required
defaultValue?[]const u8nullDefault value if missing
defaultFn?DefaultFnnullDefault value provider function
validatorsList[]const ValidatorFn&.{}Validators to run
description?[]const u8nullDescription for error messages

ValidationError ​

zig
pub const ValidationError = struct {
    key: []const u8,
    message: []const u8,
    level: Level = .err,
};
FieldTypeDefaultDescription
key[]const u8—The key that failed validation
message[]const u8—Error or warning message
levelLevel.err.err for errors, .warning for warnings

Released under the MIT License.