From 83d7f67ecaf776ea0e19061918ae881103333262 Mon Sep 17 00:00:00 2001 From: Carlos Raffellini Date: Sat, 27 Jul 2019 14:48:24 +0100 Subject: [PATCH 1/2] Issue #39 Updating spark-sql version --- build.sbt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 2360b05..9887a99 100644 --- a/build.sbt +++ b/build.sbt @@ -5,13 +5,14 @@ organization := "org.zalando" scalaVersion := "2.11.8" -libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.0.1" % Provided +libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.4.3" % Provided libraryDependencies += "com.typesafe.play" %% "play-json" % "2.5.10" dependencyOverrides ++= Set("com.fasterxml.jackson.core" % "jackson-databind" % "2.6.5") libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" scapegoatVersion := "1.3.0" + scapegoatIgnoredFiles := Seq(s"${target.value}.*.scala") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) From 1fe69cd5cd940650fbe24d0416f20c74cb8c9923 Mon Sep 17 00:00:00 2001 From: Carlos Raffellini Date: Sat, 27 Jul 2019 14:49:07 +0100 Subject: [PATCH 2/2] Issue #39 Adding test cases for references of multiple types --- build.sbt | 1 - .../jsonschema/SchemaConverterTest.scala | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 9887a99..458e50b 100644 --- a/build.sbt +++ b/build.sbt @@ -12,7 +12,6 @@ dependencyOverrides ++= Set("com.fasterxml.jackson.core" % "jackson-databind" % libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" scapegoatVersion := "1.3.0" - scapegoatIgnoredFiles := Seq(s"${target.value}.*.scala") licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/src/test/scala/org/zalando/spark/jsonschema/SchemaConverterTest.scala b/src/test/scala/org/zalando/spark/jsonschema/SchemaConverterTest.scala index 2c99a7a..e09ba28 100644 --- a/src/test/scala/org/zalando/spark/jsonschema/SchemaConverterTest.scala +++ b/src/test/scala/org/zalando/spark/jsonschema/SchemaConverterTest.scala @@ -469,4 +469,57 @@ class SchemaConverterTest extends FunSuite with Matchers with BeforeAndAfter { } } + test("Reference of multiple types should fail with strict typing") { + assertThrows[IllegalArgumentException] { + val schema = SchemaConverter.enableStrictTyping().convertContent( + """ + { + "definitions": { + "address": { + "type": ["object", "array"], + "properties": { + "street_address": { "type": "string" }, + "city": { "type": "string" }, + "state": { "type": "string" } + } + } + }, + "type": "object", + "properties": { + "billing_address": { "$ref": "#/definitions/address" } + } + } + """ + ) + } + } + + test("Reference of multiple types should default to typing when disable strict typing") { + val schema = SchemaConverter.disableStrictTyping().convertContent( + """ + { + "definitions": { + "address": { + "type": ["object", "array"], + "properties": { + "street_address": { "type": "string" }, + "city": { "type": "string" }, + "state": { "type": "string" } + } + } + }, + "type": "object", + "properties": { + "billing_address": { "$ref": "#/definitions/address" } + } + } + """ + ) + + val expected = StructType( + Seq(StructField("billing_address", StringType, nullable = false)) + ) + + assert(schema === expected) + } }