Summary

This section walked through the complete workflow for adding a custom validation option to the Spine Validation library, from declaring the option in Protobuf to making it available to the Spine Compiler.

What you covered 

  • Declare the option in Protobuf — define a Protobuf extend block targeting a standard descriptor option type, with a unique field number and an error message template that supports named placeholders.

  • Register the option — wire an OptionsProvider to register the Protobuf extension at runtime, and a ValidationOption to bind the option name to its Reaction, View, and Generator. Both are discovered via Java ServiceLoader.

  • Declare the event and view state — define a domain event emitted when the option is encountered, and a projection state message the Generator queries to accumulate option data.

  • Implement the Reaction — subscribe to FieldOptionDiscovered events, filter by option name, validate the field type and option value, and emit the domain event — or signal no reaction when the option is disabled.

  • Implement the View — build a projection that accumulates event data, making the full set of option applications queryable by the Generator.

  • Implement the Generator — query the View and produce Java validation code inlined into the generated validate() method, handling both single and repeated field cardinalities.

  • Pass the option to the Compiler — place the ValidationOption implementation on the Compiler’s user classpath via a direct spineCompiler dependency or a distributable Gradle plugin.

What’s next 

The complete source for all running examples is in the validation module of the Spine Time repository.