KReplica
Home
Playground
Guide
Home
Playground
Guide
Starter Template:
1. Basic Replication
2. Versioned DTOs
3. Nominal Typing Part I: Usage Guide
4. Nominal Typing Part II: Edge Case Examples
5. Directly Applying Annotations
6. Serialization Part I: The Apply Annotation
7. Serialization Part II: Advanced Features
8. Contextual Nesting (Unversioned)
9. Contextual Nesting (Versioned)
10. The Hide Annotation
Editor
Output
Run
Reset All
Reset All
Clear Output
package io.availe.demo.playground import io.availe.Replicate import io.availe.models.DtoVariant // Create a base, empty interface to group all versions of a schema. private interface UserAccount { // Version 1 of the schema. @Replicate.Model(variants = [DtoVariant.DATA]) private interface V1 : UserAccount { val id: Int val username: String } // Version 2 evolves the schema by adding an `email` field and a `PATCH` variant. // KReplica combines these into a single, version-aware `UserAccountSchema` sealed interface. @Replicate.Model(variants = [DtoVariant.DATA, DtoVariant.PATCH]) private interface V2 : UserAccount { val id: Int val username: String val email: String } // Notice how all the above examples follow the `V<number> : UserAccount` naming scheme. // If you wish to provide a custom name, you can do it via the @SchemaVersion annotation. // The @SchemaVersion annotation takes an Int as a parameter; let's make it Version 3. @Replicate.Model(variants = [DtoVariant.DATA, DtoVariant.PATCH]) @Replicate.SchemaVersion(3) private interface NewModel : UserAccount { val id: Int val username: String val email: String } }
Click "Run" to see the generated code.
Run
Reset All
Reset All
Clear Output