SchemaBuilder

class SchemaBuilder(schemaRegistry: SchemaRegistry? = null)

Schema Builder DSL.

Provides a fluent API for registering and validating credential schemas. Supports both JSON Schema and SHACL formats.

Example Usage:

// Register JSON Schema
trustWeave.registerSchema {
id("https://example.edu/schemas/degree")
type("JsonSchemaValidator2018")
jsonSchema {
put("$schema", "http://json-schema.org/draft-07/schema#")
put("type", "object")
put("properties", buildJsonObject {
put("degree", buildJsonObject {
put("type", "object")
put("properties", buildJsonObject {
put("type", buildJsonObject { put("type", "string") })
put("field", buildJsonObject { put("type", "string") })
})
})
})
}
}

// Register SHACL
trustWeave.registerSchema {
id("https://example.edu/schemas/degree-shacl")
type("ShaclValidator2020")
shacl {
put("@context", "https://www.w3.org/ns/shacl#")
put("sh:targetClass", "DegreeCredential")
// ... SHACL shape definition
}
}

// Validate credential
val result = trustWeave.schema("https://example.edu/schemas/degree")
.validate(credential)

Constructors

Link copied to clipboard
constructor(schemaRegistry: SchemaRegistry? = null)

Functions

Link copied to clipboard
fun definition(definition: JsonObject)

Set schema definition directly.

Link copied to clipboard
fun format(format: SchemaFormat)

Set schema format explicitly.

Link copied to clipboard
fun id(schemaId: String)

Set schema ID.

Link copied to clipboard

Build JSON Schema definition.

Link copied to clipboard

Register the schema.

Link copied to clipboard
fun shacl(block: JsonObjectBuilder.() -> Unit)

Build SHACL shape definition.

Link copied to clipboard

Validate a credential against this schema.