Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Added annotations property to EventType schema object.
Browse files Browse the repository at this point in the history
Signed-off-by: Suryanaraayan Balachandher <[email protected]>
  • Loading branch information
Suryanaraayan Balachandher committed Dec 2, 2022
1 parent 4d38d7d commit c7b4499
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/main/scala/org/zalando/kanadi/api/EventTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -327,14 +329,15 @@ 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,
updatedAt: Option[OffsetDateTime] = None
)

object EventType {
implicit val eventTypeEncoder: Encoder[EventType] = Encoder.forProduct19(
implicit val eventTypeEncoder: Encoder[EventType] = Encoder.forProduct20(
"name",
"owning_application",
"category",
Expand All @@ -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",
Expand All @@ -372,6 +376,7 @@ object EventType {
"write_scopes",
"read_scopes",
"audience",
"annotations",
"ordering_key_fields",
"ordering_instance_ids",
"created_at",
Expand Down
40 changes: 37 additions & 3 deletions src/test/scala/org/zalando/kanadi/api/JsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package org.zalando.kanadi
package api

import java.util.UUID

import cats.syntax.either._
import cats.instances.either._
import org.specs2.Specification
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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -84,6 +103,13 @@ 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)

Expand All @@ -93,4 +119,12 @@ 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
}
}

0 comments on commit c7b4499

Please sign in to comment.