Skip to content

Instantly share code, notes, and snippets.

@afranzi
Created March 13, 2019 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afranzi/4f4d17e2072f3e03a0a951cfd36893e8 to your computer and use it in GitHub Desktop.
Save afranzi/4f4d17e2072f3e03a0a951cfd36893e8 to your computer and use it in GitHub Desktop.
Evolve json events using JSLT expressions
def evolve(event: ValidationResult[JsonNode]): EvolutionResult[JsonNode] = {
val schemasReferenced: Seq[SchemaReferenced] = event.schemasReferenced
val json = event.event
val schemasToEvolve = schemasReferenced
.filter { case SchemaReferenced(_, schemaRef) => hasEvolution(schemaRef) }
val eventEvolved = schemasToEvolve
.foldLeft(json) {
case (jsonEvent: JsonNode, SchemaReferenced(location, schemaRef)) =>
val evolutionExpr = buildEvolutionExpr(location, schemaRef)
val expr: Expression = Parser.compileString(evolutionExpr)
expr(jsonEvent)
}
EvolutionResult(
event = json,
evolved = eventEvolved,
schemasReferenced = schemasReferenced,
schemasEvolved = schemasToEvolve
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment