Skip to content

Commit

Permalink
Move tests to Weaver and incorporate Scalafix
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinlfer committed Jul 16, 2024
1 parent d1aeb00 commit 4060e5c
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 156 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ jobs:
- name: Check that workflows are up to date
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck

- name: Build project
run: sbt '++ ${{ matrix.scala }}' test
- run: sbt '++ ${{ matrix.scala }}' lintEnforce test

- name: Compress target directories
run: tar cf targets.tar target project/target
Expand Down
7 changes: 7 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules = [OrganizeImports]

OrganizeImports {
removeUnused = false
groupedImports = Merge
targetDialect = Scala3
}
25 changes: 19 additions & 6 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version = 3.8.2
maxColumn = 120
version = "3.8.2"
maxColumn = 140
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
Expand All @@ -12,7 +12,20 @@ danglingParentheses.preset = true
optIn.annotationNewlines = true
newlines.alwaysBeforeMultilineDef = false
runner.dialect = scala3
rewrite {
rules = [AvoidInfix, PreferCurlyFors, SortImports, RedundantBraces, RedundantParens]
redundantBraces.maxLines = 1
}
rewrite.rules = [RedundantBraces]

project.excludePaths = ["glob:**/scalafix/input/**", "glob:**/scalafix/output/**"]

rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.removeOptionalBraces = yes
rewrite.redundantBraces.generalExpressions = true

rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}

fileOverride {
"glob:**/*.sbt" = sbt1
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.watcherExclude": {
"**/target": true
}
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## FS2 Kafka JsonSchema support ##
## FS2 Kafka JsonSchema

[![Continuous Integration](https://github.com/kaizen-solutions/fs2-kafka-jsonschema-support/actions/workflows/ci.yml/badge.svg)](https://github.com/kaizen-solutions/fs2-kafka-jsonschema-support/actions/workflows/ci.yml)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.kaizen-solutions/fs2-kafka-jsonschema-support_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.kaizen-solutions/fs2-kafka-jsonschema-support_2.13)
[![JitPack](https://jitpack.io/v/kaizen-solutions/fs2-kafka-jsonschema-support.svg)](https://jitpack.io/#kaizen-solutions/fs2-kafka-jsonschema-support)
[![Continuous Integration](https://github.com/kaizen-solutions/fs2-kafka-jsonschema/actions/workflows/ci.yml/badge.svg)](https://github.com/kaizen-solutions/fs2-kafka-jsonschema/actions/workflows/ci.yml)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.kaizen-solutions/fs2-kafka-jsonschema_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.kaizen-solutions/fs2-kafka-jsonschema_2.13)
[![JitPack](https://jitpack.io/v/kaizen-solutions/fs2-kafka-jsonschema.svg)](https://jitpack.io/#kaizen-solutions/fs2-kafka-jsonschema)


Provides FS2 Kafka `Serializer`s and `Deserializer`s that provide integration with Confluent Schema Registry for JSON messages with JSON Schemas.
Provides FS2 Kafka `Serializer`s and `Deserializer`s that provide integration with Confluent Schema Registry for JSON messages with JSON Schemas.

__Note:__ _This library only works with Scala 3.3.x and above._ For Scala 2.x, see [here](https://github.com/kaizen-solutions/fs2-kafka-jsonschema-support).

Expand Down
31 changes: 20 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ inThisBuild {
ScalacOptions.privateKindProjector
)
),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
versionScheme := Some("early-semver"),
githubWorkflowJavaVersions := List(JavaSpec.temurin("17")),
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowPublishTargetBranches := Seq(
RefPredicate.StartsWith(Ref.Tag("v")),
RefPredicate.Equals(Ref.Branch("main"))
),
githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("lintEnforce", "test"))
),
githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
commands = List("ci-release"),
Expand Down Expand Up @@ -60,22 +65,26 @@ lazy val root =
.settings(
name := "fs2-kafka-jsonschema",
libraryDependencies ++= {
val circe = "io.circe"
val fd4s = "com.github.fd4s"
val tapir = "com.softwaremill.sttp.tapir"
val fs2KafkaV = "3.5.1"
val tapirV = "1.10.13"

Seq(
fd4s %% "fs2-kafka" % fs2KafkaV,
tapir %% "tapir-json-pickler" % tapirV,
tapir %% "tapir-apispec-docs" % tapirV,
"com.softwaremill.sttp.apispec" %% "jsonschema-circe" % "0.10.0",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0",
"org.typelevel" %% "munit-cats-effect" % "2.0.0-M3" % Test,
"com.dimafeng" %% "testcontainers-scala-munit" % "0.41.4" % Test,
"ch.qos.logback" % "logback-classic" % "1.5.6" % Test,
"io.confluent" % "kafka-json-schema-serializer" % "7.6.1"
fd4s %% "fs2-kafka" % fs2KafkaV,
tapir %% "tapir-json-pickler" % tapirV,
tapir %% "tapir-apispec-docs" % tapirV,
"com.softwaremill.sttp.apispec" %% "jsonschema-circe" % "0.10.0",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0",
"com.disneystreaming" %% "weaver-cats" % "0.8.4" % Test,
"io.github.embeddedkafka" %% "embedded-kafka-schema-registry" % "7.6.1.1" % Test,
"ch.qos.logback" % "logback-classic" % "1.5.6" % Test,
"io.confluent" % "kafka-json-schema-serializer" % "7.6.1"
)
}
},
excludeDependencies += "org.scala-lang.modules" % "scala-collection-compat_2.13",
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
)

addCommandAlias("lint", "; scalafmtAll; scalafixAll")
addCommandAlias("lintEnforce", "; scalafmtCheckAll; scalafixAll --check")
8 changes: 8 additions & 0 deletions project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// format: off
// DO NOT EDIT! This file is auto-generated.

// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.6.0")

// format: on
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.3")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")

libraryDependencies += "org.typelevel" %% "scalac-options" % "0.1.5"
8 changes: 8 additions & 0 deletions project/project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// format: off
// DO NOT EDIT! This file is auto-generated.

// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.6.0")

// format: on
8 changes: 8 additions & 0 deletions project/project/project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// format: off
// DO NOT EDIT! This file is auto-generated.

// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.6.0")

// format: on
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import cats.effect.{Resource, Sync}
import cats.syntax.all.*
import com.fasterxml.jackson.databind.JsonNode
import fs2.kafka.*
import sttp.tapir.json.pickler.Pickler
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer
import sttp.tapir.json.pickler.Pickler

import scala.jdk.CollectionConverters.*

private[jsonschema] object JsonSchemaDeserializer:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package io.kaizensolutions.jsonschema

import cats.effect.Resource
import cats.effect.Sync
import cats.effect.{Resource, Sync}
import com.fasterxml.jackson.databind.JsonNode
import fs2.kafka.*
import io.confluent.kafka.schemaregistry.SchemaProvider
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import io.confluent.kafka.schemaregistry.client.{CachedSchemaRegistryClient, SchemaRegistryClient}
import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig.*
import io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializerConfig.*
import sttp.tapir.json.pickler.Pickler

import scala.jdk.CollectionConverters.*

object JsonSchemaDeserializerSettings {
object JsonSchemaDeserializerSettings:
val default: JsonSchemaDeserializerSettings = JsonSchemaDeserializerSettings()
}

final case class JsonSchemaDeserializerSettings(
schemaRegistryUrl: String = "http://localhost:8081",
failOnUnknownProperties: Boolean = true,
failOnInvalidSchema: Boolean = false,
cacheCapacity: Int = 1024,
client: Option[SchemaRegistryClient] = None
) { self =>
):
self =>
def withSchemaRegistryUrl(url: String): JsonSchemaDeserializerSettings =
self.copy(schemaRegistryUrl = url)

Expand Down Expand Up @@ -72,4 +70,3 @@ final case class JsonSchemaDeserializerSettings(
val release = (client: SchemaRegistryClient) => sync.delay(client.close())
Resource.make(acquire)(release)
.flatMap(client => JsonSchemaDeserializer.create(isKey, confluentConfig, client))
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package io.kaizensolutions.jsonschema

import cats.effect.Resource
import cats.effect.Sync
import cats.effect.{Resource, Sync}
import cats.syntax.functor.*
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import fs2.kafka.*
import io.circe.syntax.*
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import io.confluent.kafka.schemaregistry.json.JsonSchema
import io.confluent.kafka.schemaregistry.json.JsonSchemaUtils
import io.confluent.kafka.schemaregistry.json.{JsonSchema, JsonSchemaUtils}
import io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializer
import sttp.apispec.{ExampleSingleValue, SchemaType}
import sttp.apispec.circe.*
import sttp.apispec.{ExampleSingleValue, SchemaType}
import sttp.tapir.docs.apispec.schema.*
import sttp.tapir.json.pickler.Pickler

Expand All @@ -27,9 +24,7 @@ private[jsonschema] object JsonSchemaSerializer:
envelopeMode: Boolean
)(using p: Pickler[A], sync: Sync[F]): Resource[F, Serializer[F, A]] =
Resource
.make(sync.delay(KafkaJsonSchemaSerializer[JsonNode](client, confluentConfig)))(client =>
sync.delay(client.close())
)
.make(sync.delay(KafkaJsonSchemaSerializer[JsonNode](client, confluentConfig)))(client => sync.delay(client.close()))
.evalTap: client =>
sync.delay(client.configure(confluentConfig, isKey))
.evalMap: underlying =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package io.kaizensolutions.jsonschema
import cats.effect.Resource
import cats.effect.Sync
import cats.effect.{Resource, Sync}
import com.fasterxml.jackson.databind.ObjectMapper
import fs2.kafka.*
import io.circe.generic.auto
import io.confluent.kafka.schemaregistry.SchemaProvider
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider
import io.confluent.kafka.schemaregistry.json.SpecificationVersion
import io.confluent.kafka.schemaregistry.client.{CachedSchemaRegistryClient, SchemaRegistryClient}
import io.confluent.kafka.schemaregistry.json.{JsonSchemaProvider, SpecificationVersion}
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig.*
import io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializerConfig.*
import sttp.tapir.json.pickler.Pickler

import java.util.Locale
import scala.jdk.CollectionConverters.*
import io.circe.generic.auto

object JsonSchemaSerializerSettings:
val default: JsonSchemaSerializerSettings = JsonSchemaSerializerSettings()
Expand Down
Loading

0 comments on commit 4060e5c

Please sign in to comment.