Skip to content

Commit

Permalink
Merge ac97cb7 into 3e0bea9
Browse files Browse the repository at this point in the history
  • Loading branch information
chuwy committed Jun 17, 2020
2 parents 3e0bea9 + ac97cb7 commit 9d9ab3b
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 39 deletions.
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ language: scala
os: linux
dist: trusty
scala:
- 2.12.8
- 2.12.11
- 2.13.2
jdk:
- openjdk8
addons:
hostname: short-hostname
before_install: 'openssl aes-256-cbc -K $encrypted_38b5cd286219_key -iv $encrypted_38b5cd286219_iv -in project/travis-deploy-key.enc -out project/travis-deploy-key -d'
before_install:
- openssl aes-256-cbc -K $encrypted_38b5cd286219_key -iv $encrypted_38b5cd286219_iv -in project/travis-deploy-key.enc -out project/travis-deploy-key -d
- npm install -g snyk
script:
- sbt clean coverage +test
- sbt coverageReport
after_success: "sbt coveralls"
after_success:
- snyk monitor
- sbt coveralls
deploy:
cleanup: false
provider: script
script: "./.travis/deploy.sh $TRAVIS_TAG"
on:
condition: '"${TRAVIS_SCALA_VERSION}" == "2.12.8"'
condition: '"${TRAVIS_SCALA_VERSION}" == "2.12.11"'
tags: true
env:
global:
Expand All @@ -28,3 +32,4 @@ env:
- secure: ZdJH16Iz79TTwPCha92BuekZP07QsLAxMqaG4liH45ncK4TE+xfEE0lAmt2SqonPodXDbx94cFwjTEum0xFsEOp1ASsz393i265+qVKT+WwumpMe1/4Ta9UF6bAZMBQSeikgW7Qnh7uN2DVUKJ9LNrCg3xlBReWeqJC/1AjD+TM=
- ENCRYPTION_LABEL: 38b5cd286219
- secure: PQ/P9MzZt5vczMZBgrKQD2+lvFkwJJI644MxxUf1xX0SBocvyuB5xkjdlgmbQHtRW90WgiSJJ2AO+lj/SNc61zHyZaC1YrrPzbJZPTNzihcsWvKBJKdMOX3OpN3+eXmY5JgKcZ7MRiCIetuRkZ8LkdThl8DCFGvtPmNHayqpCOk=
- secure: cAcmKufGhrguRB471CXwhcqBrcbQfgqhnRoH7VjlISpIKBEPAV6x8inrkGfaT99KCDtqLdDT59bZUy8IBiqn9Xijzd9dZkM6uU8WCecLN0gnE1WNPCicikSNYDOLnK+tFkWpZgfqy+jCu6BpRa49audc7rpy4tGv2w+JyIr9clo=
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 1.0.2 (2020-06-18)
--------------------------
Replace Map with SortedMap in ResolutionError (#147)
Remove exclusiveMinimum and exclusiveMaximum properties from from metaschema (#132)
Bump Scala to 2.12.11 (#146)
Bump slf4j to 1.7.30 (#145)
Bump jackson-databind to 2.10.3 (#143)

Version 1.0.1 (2020-06-11)
--------------------------
Bump SBT to 1.3.12 (#142)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Iglu Scala Client is used extensively in **[Snowplow][snowplow-repo]** to valida

## Installation

The latest version of Iglu Scala Client is 1.0.1, which currently works with Scala 2.12 and 2.13.
The latest version of Iglu Scala Client is 1.0.2, which currently works with Scala 2.12 and 2.13.

If you're using SBT, add the following lines to your build file:

```scala
val igluClient = "com.snowplowanalytics" %% "iglu-scala-client" % "1.0.1"
val igluClient = "com.snowplowanalytics" %% "iglu-scala-client" % "1.0.2"
```

## API
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
lazy val root = (project in file("."))
.settings(
name := "iglu-scala-client",
version := "1.0.1",
version := "1.0.2-M2",
description := "Scala client and resolver for Iglu schema repositories"
)
.enablePlugins(SiteScaladocPlugin, GhpagesPlugin, PreprocessPlugin)
Expand Down
2 changes: 1 addition & 1 deletion project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object BuildSettings {
lazy val buildSettings = Seq[Setting[_]](
organization := "com.snowplowanalytics",
scalaVersion := "2.13.2",
crossScalaVersions := Seq("2.12.8", "2.13.2"),
crossScalaVersions := Seq("2.12.11", "2.13.2"),

addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.0" cross CrossVersion.full),

Expand Down
8 changes: 4 additions & 4 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ object Dependencies {
object V {
// Java
val validator = "1.0.39"
val slf4j = "1.7.26"
val slf4j = "1.7.30"
val jackson = "2.10.3"
// Scala
val igluCore = "1.0.0"
val cats = "2.1.1"
Expand All @@ -30,9 +31,8 @@ object Dependencies {
object Libraries {
// Java
// Excluding binary-incompatible Jackson and include the latest from 2.9 series
val validatorFull = "com.networknt" % "json-schema-validator" % V.validator
val validator = validatorFull.exclude("com.fasterxml.jackson.core", "jackson-databind")
val jackson = "com.fasterxml.jackson.core" % "jackson-databind" % "2.9.10.1"
val validator = "com.networknt" % "json-schema-validator" % V.validator
val jackson = "com.fasterxml.jackson.core" % "jackson-databind" % V.jackson

// Scala
val igluCore = "com.snowplowanalytics" %% "iglu-core" % V.igluCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import java.time.Instant
import cats.Show
import cats.syntax.show._
import cats.syntax.either._

import io.circe.{Decoder, DecodingFailure, Encoder, Json}
import io.circe.syntax._

import validator.ValidatorError
import resolver.LookupHistory
import resolver.registries.RegistryError

import scala.collection.immutable.SortedMap

/** Common type for Resolver's and Validator's errors */
sealed trait ClientError extends Product with Serializable {
def getMessage: String =
Expand All @@ -34,7 +34,7 @@ sealed trait ClientError extends Product with Serializable {
object ClientError {

/** Error happened during schema resolution step */
final case class ResolutionError(value: Map[String, LookupHistory]) extends ClientError {
final case class ResolutionError(value: SortedMap[String, LookupHistory]) extends ClientError {
def isNotFound: Boolean =
value.values.flatMap(_.errors).forall(_ == RegistryError.NotFound)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ object ClientError {
.downField("lookupHistory")
.as[List[RepoLookupHistory]]
.map { history =>
ResolutionError(history.map(_.toField).toMap)
ResolutionError(SortedMap[String, LookupHistory]() ++ history.map(_.toField).toMap)
}
case "ValidationError" =>
cursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import cats.{Applicative, Id, Monad}
import java.time.Instant

import scala.concurrent.duration.MILLISECONDS

import cats.data._
import cats.effect.Clock
import cats.implicits._

import io.circe.{Decoder, DecodingFailure, HCursor, Json}

import com.snowplowanalytics.iglu.core.{
SchemaCriterion,
SchemaKey,
Expand All @@ -34,7 +31,6 @@ import com.snowplowanalytics.iglu.core.{
SelfDescribingSchema
}
import com.snowplowanalytics.iglu.core.circe.CirceIgluCodecs._

import com.snowplowanalytics.iglu.client.ClientError.ResolutionError
import com.snowplowanalytics.iglu.client.resolver.registries.{
Registry,
Expand All @@ -43,6 +39,8 @@ import com.snowplowanalytics.iglu.client.resolver.registries.{
}
import com.snowplowanalytics.iglu.client.resolver.registries.Registry.Get

import scala.collection.immutable.SortedMap

/** Resolves schemas from one or more Iglu schema registries */
final case class Resolver[F[_]](repos: List[Registry], cache: Option[ResolverCache[F]]) {
import Resolver._
Expand Down Expand Up @@ -295,7 +293,9 @@ object Resolver {

private def postProcess[F[_], A](result: Either[LookupFailureMap, A]) =
result.leftMap { failure =>
ResolutionError(failure.map { case (key, value) => (key.config.name, value) })
ResolutionError(SortedMap[String, LookupHistory]() ++ failure.map {
case (key, value) => (key.config.name, value)
})
}

private def matchConfig[F[_]: Applicative](datum: SelfDescribingData[Json]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ object CirceValidator extends Validator[Json] {
| "default": {},
| "multipleOf": {
| "type": "number",
| "minimum": 0,
| "exclusiveMinimum": true
| "minimum": 0
| },
| "maximum": {
| "type": "number"
Expand All @@ -90,10 +89,6 @@ object CirceValidator extends Validator[Json] {
| "minimum": {
| "type": "number"
| },
| "exclusiveMinimum": {
| "type": "boolean",
| "default": false
| },
| "maxLength": { "$ref": "#/definitions/positiveInteger" },
| "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
| "pattern": {
Expand Down Expand Up @@ -177,8 +172,7 @@ object CirceValidator extends Validator[Json] {
| "not": { "$ref": "#" }
| },
| "dependencies": {
| "exclusiveMaximum": [ "maximum" ],
| "exclusiveMinimum": [ "minimum" ]
| "exclusiveMaximum": [ "maximum" ]
| },
| "default": {}
|}""".stripMargin
Expand Down
10 changes: 7 additions & 3 deletions src/main/scala/io/circe/jackson/snowplow/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ package object snowplow {
}
}
},
TextNode.valueOf(_),
s => TextNode.valueOf(s),
array => JsonNodeFactory.instance.arrayNode.addAll(array.map(circeToJackson).asJava),
obj =>
JsonNodeFactory.instance.objectNode
.setAll(obj.toMap.map { case (k, v) => (k, circeToJackson(v)) }.toMap.asJava)
objectNodeSetAll(JsonNodeFactory.instance.objectNode, obj.toMap.map {
case (k, v) => (k, circeToJackson(v))
}.asJava)
)

def objectNodeSetAll(node: ObjectNode, fields: java.util.Map[String, JsonNode]): JsonNode =
node.setAll[JsonNode](fields)

private def getJsonNodeFromStringContent(content: String): JsonNode =
mapper.readTree(content)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
package com.snowplowanalytics.iglu.client

import cats.data.NonEmptyList

import io.circe.syntax._
import io.circe.literal._

import com.snowplowanalytics.iglu.client.resolver.LookupHistory
import com.snowplowanalytics.iglu.client.resolver.registries.RegistryError
import com.snowplowanalytics.iglu.client.validator.{ValidatorError, ValidatorReport}

import org.specs2.Specification

import scala.collection.immutable.SortedMap

class ClientErrorSpec extends Specification {
def is =
s2"""
Expand All @@ -32,7 +31,7 @@ class ClientErrorSpec extends Specification {

def e1 = {
val error: ClientError = ClientError.ResolutionError(
Map(
SortedMap(
"First repo" -> LookupHistory(
Set(RegistryError.NotFound, RegistryError.RepoFailure("Server outage")),
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ package com.snowplowanalytics.iglu.client.resolver
import java.time.Instant
import java.net.URI

import scala.collection.immutable.SortedMap

// Cats
import cats.Id
import cats.effect.IO
Expand Down Expand Up @@ -132,7 +134,7 @@ class ResolverSpec extends Specification with DataTables with ValidatedMatchers

val schemaKey = SchemaKey("com.acme.icarus", "wing", "jsonschema", SchemaVer.Full(1, 0, 0))
val expected = ResolutionError(
Map(
SortedMap(
"Iglu Client Embedded" -> LookupHistory(Set(RegistryError.NotFound), 1, SpecHelpers.now),
"Iglu Test Embedded" -> LookupHistory(Set(RegistryError.NotFound), 1, SpecHelpers.now)
))
Expand All @@ -151,7 +153,7 @@ class ResolverSpec extends Specification with DataTables with ValidatedMatchers
"jsonschema",
SchemaVer.Full(1, 0, 0))
val expected = ResolutionError(
Map(
SortedMap(
"Iglu Client Embedded" -> LookupHistory(Set(RegistryError.NotFound), 1, SpecHelpers.now),
"Iglu Test Embedded" -> LookupHistory(
Set(RegistryError.RepoFailure("ParsingFailure: exhausted input")),
Expand Down Expand Up @@ -312,7 +314,7 @@ class ResolverSpec extends Specification with DataTables with ValidatedMatchers
Nil)

val expected = ResolutionError(
Map(
SortedMap(
"Mock Repo 1" -> LookupHistory(Set(error1, error2), 2, Instant.ofEpochMilli(2008L)),
"Mock Repo 2" -> LookupHistory(Set(error3, error4), 2, Instant.ofEpochMilli(2009L)),
"Iglu Client Embedded" -> LookupHistory(
Expand Down

0 comments on commit 9d9ab3b

Please sign in to comment.