Chronicle.Schemas.JsonSchemaGenerator (cratis_chronicle v1.0.3)

Copy Markdown View Source

Generates JSON schemas for struct-backed event types and read models.

This is the single source of truth for schema generation shared by event type registration (Chronicle.EventTypes) and read model registration (Chronicle.Registration.Coordinator). Generating both through one path keeps property typing consistent and ensures compliance (PII) metadata is always embedded the same way.

Fields marked with Chronicle.Compliance.pii/1,2 are emitted with a compliance array on their property schema, which the Chronicle kernel reads to apply compliance-aware encryption.

Summary

Functions

Generates a JSON schema string for a struct module.

Functions

generate(module, opts \\ [])

@spec generate(
  module(),
  keyword()
) :: String.t()

Generates a JSON schema string for a struct module.

Options

  • :key_transform — how struct field names are rendered as schema property names. :camel renders snake_case as camelCase (used for event types, whose content is serialized as camelCase); :identity keeps the field name as-is (used for read models, whose stored properties are snake_case). Defaults to :identity.

PII fields are discovered through the module's __chronicle_pii__/0 accessor when present.