Docs / ArchitectureKit / Guides / Registering Event Schemas
Registering Event Schemas
To have the database validate events of a type, implement the Schema function on the event and return a JSON schema. This makes the event a SchemaProvider:
func (BookAcquired) Schema() map[string]any {
return map[string]any{
"type": "object",
"properties": map[string]any{
"title": map[string]any{"type": "string"},
"author": map[string]any{"type": "string"},
"isbn": map[string]any{"type": "string"},
},
"required": []string{
"title",
"author",
"isbn",
},
"additionalProperties": false,
}
}
The Evolve function collects the schemas of all events that implement Schema. To get them as a slice of EventSchema, each with the fields EventType and Schema, call the Schemas function on the state. Then hand them over to the RegisterSchemas function of the store:
err := store.RegisterSchemas(bookState.Schemas())
if err != nil {
// ...
}
RegisterSchemas accepts the schemas of several states at once. Event types that are already registered count as success, so you can call the function on every start.