From 40d6b45ff8fe09f1830144e3f9dbad67a755d4e7 Mon Sep 17 00:00:00 2001 From: Grigorii Chudnov Date: Fri, 2 Dec 2022 15:45:27 +0100 Subject: [PATCH 1/2] start 0.10.2-SNAPSHOT (#201) * Setting version to 0.10.2-SNAPSHOT Signed-off-by: Grigorii Chudnov --- version.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.sbt b/version.sbt index aa2cbb4..e1b9bbd 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -ThisBuild / version := "0.10.1-SNAPSHOT" +ThisBuild / version := "0.10.2-SNAPSHOT" From 14ee5602ed48d892b2e60fd74250bc34b9dd6cbf Mon Sep 17 00:00:00 2001 From: Suryanaraayan Balachandher Date: Fri, 2 Dec 2022 16:07:55 +0100 Subject: [PATCH 2/2] Added annotations property to EventType schema object. (#202) Signed-off-by: Suryanaraayan Balachandher Signed-off-by: Suryanaraayan Balachandher Co-authored-by: Suryanaraayan Balachandher --- .../org/zalando/kanadi/api/EventTypes.scala | 9 +++- .../org/zalando/kanadi/api/JsonSpec.scala | 41 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main/scala/org/zalando/kanadi/api/EventTypes.scala b/src/main/scala/org/zalando/kanadi/api/EventTypes.scala index 81b16de..4f74cbd 100644 --- a/src/main/scala/org/zalando/kanadi/api/EventTypes.scala +++ b/src/main/scala/org/zalando/kanadi/api/EventTypes.scala @@ -300,6 +300,8 @@ object EventTypeOptions { * least one of the scopes in this list. If no scopes provided then anyone can consume from this event type. * @param audience * Intended target audience of the event type. + * @param annotations + * Annotations of the Nakadi resource. * @param orderingKeyFields * This is an optional field which can be useful in case the producer wants to communicate the complete order across * all the events published to all the partitions. @@ -327,6 +329,7 @@ final case class EventType( writeScopes: Option[List[WriteScope]] = None, readScopes: Option[List[ReadScope]] = None, audience: Option[Audience] = None, + annotations: Option[Map[String, String]] = None, orderingKeyFields: Option[List[String]] = None, orderingInstanceIds: Option[List[String]] = None, createdAt: Option[OffsetDateTime] = None, @@ -334,7 +337,7 @@ final case class EventType( ) object EventType { - implicit val eventTypeEncoder: Encoder[EventType] = Encoder.forProduct19( + implicit val eventTypeEncoder: Encoder[EventType] = Encoder.forProduct20( "name", "owning_application", "category", @@ -350,13 +353,14 @@ object EventType { "write_scopes", "read_scopes", "audience", + "annotations", "ordering_key_fields", "ordering_instance_ids", "created_at", "updated_at" )(x => EventType.unapply(x).get) - implicit val eventTypeDecoder: Decoder[EventType] = Decoder.forProduct19( + implicit val eventTypeDecoder: Decoder[EventType] = Decoder.forProduct20( "name", "owning_application", "category", @@ -372,6 +376,7 @@ object EventType { "write_scopes", "read_scopes", "audience", + "annotations", "ordering_key_fields", "ordering_instance_ids", "created_at", diff --git a/src/test/scala/org/zalando/kanadi/api/JsonSpec.scala b/src/test/scala/org/zalando/kanadi/api/JsonSpec.scala index ea3e3cb..0d636c4 100644 --- a/src/test/scala/org/zalando/kanadi/api/JsonSpec.scala +++ b/src/test/scala/org/zalando/kanadi/api/JsonSpec.scala @@ -2,7 +2,6 @@ package org.zalando.kanadi package api import java.util.UUID - import cats.syntax.either._ import cats.instances.either._ import org.specs2.Specification @@ -10,9 +9,9 @@ import org.specs2.specification.core.SpecStructure import io.circe._ import io.circe.parser._ import io.circe.syntax._ -import org.zalando.kanadi.models.{EventId, SpanCtx, PublishedBy} -import java.time.OffsetDateTime +import org.zalando.kanadi.models.{EventId, EventTypeName, PublishedBy, SpanCtx} +import java.time.OffsetDateTime import io.circe.CursorOp.DownField class JsonSpec extends Specification { @@ -23,6 +22,8 @@ class JsonSpec extends Specification { SpanCtx decoding example $decodeSpnCtx SpanCtx encoding example $encodeSpnCtx SpanCtx fail decoding example $badDecodeSpnCtx + Decoding EventType example $decodeEventTypesAnnotationsCtx + Encoding EventType example $encodeEventTypesAnnotationsCtx """ val uuid = UUID.randomUUID() @@ -55,6 +56,24 @@ class JsonSpec extends Specification { val undefinedEventJson = s"{$coreEventJson}" + val eventTypeWithAnnotationsJson = + """{ + | "name" : "order.order_cancelled", + | "owning_application" : "price-service", + | "category" : "undefined", + | "enrichment_strategies" : [ + | "metadata_enrichment" + | ], + | "schema" : { + | "type" : "json_schema", + | "schema" : "{\"type\":\"object\"}" + | }, + | "annotations" : { + | "nakadi.io/internal-event-type" : "true", + | "criticality" : "low" + | } + |}""".stripMargin + def businessEvent = decode[Event[SomeEvent]](businessEventJson) must beRight(Event.Business(testEvent, md)) @@ -84,6 +103,15 @@ class JsonSpec extends Specification { ))) ) + val eventTypeWithAnnotationsData = EventType( + name = EventTypeName("order.order_cancelled"), + owningApplication = "price-service", + category = Category.Undefined, + enrichmentStrategies = List(EnrichmentStrategy.MetadataEnrichment), + schema = EventTypeSchema.anyJsonObject, + annotations = Some(Map("nakadi.io/internal-event-type" -> "true", "criticality" -> "low")) + ) + def decodeSpnCtx = decode[Metadata](spanCtxJson) must beRight(spanCtxEventMetadata) @@ -93,4 +121,11 @@ class JsonSpec extends Specification { def badDecodeSpnCtx = decode[Metadata](spanCtxBadJson) must beLeft( DecodingFailure("String", List(DownField("ot-tracer-traceid"), DownField("span_ctx")))) + + def decodeEventTypesAnnotationsCtx = + decode[EventType](eventTypeWithAnnotationsJson) must beRight(eventTypeWithAnnotationsData) + + def encodeEventTypesAnnotationsCtx = + eventTypeWithAnnotationsData.asJson.printWith( + Printer.spaces2.copy(dropNullValues = true)) mustEqual eventTypeWithAnnotationsJson }