SchemaGuard
You give it data and a schema. It returns a clear Result β valid data, or a plain-English reason why not. Never a crash.
Every payload crossing your boundary β API body, config file, upload β either matches the shape you expect, or it doesnβt.
SchemaGuard answers that in one handshake:
Result.success β data is safe to use as-is.Result.failure β what failed, and where.No exceptions thrown for βbad shape.β No half-processed data leaking through.
What it replaces
- Annotate a class; hope the framework wires it
- Reflection scans objects at runtime
- Bad data throws deep in unrelated code
- Debug by chasing a stack trace
- Write the schema once as a plain
.axiomfile - No annotations, no reflection, no scanning
- Bad data never throws β you get a
Result - The failure message names the field and rule
How you actually use it (2.0.0)
Content is byte[] (or an already-parsed map). Three steps. Thatβs the whole interaction.
final var result = SchemaGuard
.checkContent(contentBytes)
.basedOnSchemaInPath("user-profile")
.withAxiomParser();
final var data = SchemaGuard
.checkContent(substance) // substance = request body as byte[]
.basedOnSchemaInPath("schemas/account_query_schema")
.withParser(bytes -> JsonParser.take(bytes)
.openBuffer()
.ensureRootIsObject()
.parseObject())
.getOrThrow();
final var result = SchemaGuard
.checkContent(myPersistentMap)
.basedOnSchemaInPath("user-profile")
.withAxiomParser();
Hand it byte[] or a PersistentMap.
Name the schema file via basedOnSchemaInPath.
Get a Result β never a structural crash.
checkContent(String)is gone. UsecheckContent(byte[])orcheckContent(PersistentMap).withParseris nowFunction<byte[], PersistentMap<String, Object>>.
Writing a schema: the .axiom file
A schema is a plain file, not code. Drop it under schemas/, reference it by path β nothing to compile or annotate.
{
required: [status, limit]
properties: {
status: {
type: string
enum: [ACTIVE, INACTIVE, SUSPENDED, PENDING]
}
limit: {
type: integer
min: 1
max: 1000
description: Maximum records per fetch.
}
}
}
Part of axiom-language Β· depends on axiom-sovereign + axiom