Skip to content

Commit 8e5eaac

Browse files
authored
re-enable scala3 tests (#167)
1 parent 076b8ca commit 8e5eaac

File tree

6 files changed

+59
-46
lines changed

6 files changed

+59
-46
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,9 @@ jobs:
5959
run: sbt '++${{ matrix.scala }}' coverage test coverageReport
6060

6161
- name: Scala build
62-
if: '!startsWith(matrix.scala, ''2.13'') && !startsWith(matrix.scala, ''3.0'')'
62+
if: '!startsWith(matrix.scala, ''2.13''))'
6363
run: sbt '++${{ matrix.scala }}' test
6464

65-
- name: Scala compile
66-
if: startsWith(matrix.scala, '3.0')
67-
run: sbt '++${{ matrix.scala }}' compile
68-
6965
- name: Publish to Codecov.io
7066
if: startsWith(matrix.scala, '2.13')
7167
uses: codecov/codecov-action@v2

build.sbt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ libraryDependencies ++= Seq(
7373
"org.slf4j" % "slf4j-simple" % "1.7.36" % Test
7474
)
7575
libraryDependencies ++= {
76-
CrossVersion.partialVersion(Keys.scalaVersion.value) match {
77-
case Some((3, _)) => Seq()
78-
case _ => Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
76+
if (scalaReleaseVersion.value == 2) {
77+
Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value)
78+
} else {
79+
Seq()
7980
}
8081
}
8182

@@ -85,14 +86,14 @@ Test / parallelExecution := false
8586

8687
startYear := Some(2014)
8788

88-
licenses := Seq(("Apache License 2.0", new URL("http://www.apache.org/licenses/LICENSE-2.0.html")))
89+
licenses := Seq(("Apache License 2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.html")))
8990

9091
pomExtra := {
9192
pomExtra.value ++ Group(
92-
<issueManagement>
93-
<system>github</system>
94-
<url>https://github.com/swagger-api/swagger-scala-module/issues</url>
95-
</issueManagement>
93+
<issueManagement>
94+
<system>github</system>
95+
<url>https://github.com/swagger-api/swagger-scala-module/issues</url>
96+
</issueManagement>
9697
<developers>
9798
<developer>
9899
<id>fehguy</id>
@@ -110,8 +111,7 @@ pomExtra := {
110111

111112
ThisBuild / githubWorkflowBuild := Seq(
112113
WorkflowStep.Sbt(List("coverage", "test", "coverageReport"), name = Some("Scala 2.13 build"), cond = Some("startsWith(matrix.scala, '2.13')")),
113-
WorkflowStep.Sbt(List("test"), name = Some("Scala build"), cond = Some("!startsWith(matrix.scala, '2.13') && !startsWith(matrix.scala, '3.0')")),
114-
WorkflowStep.Sbt(List("compile"), name = Some("Scala compile"), cond = Some("startsWith(matrix.scala, '3.0')")),
114+
WorkflowStep.Sbt(List("test"), name = Some("Scala build"), cond = Some("!startsWith(matrix.scala, '2.13'))"))
115115
)
116116

117117
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec(Zulu, "8"))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.swagger.scala.converter
2+
3+
object RuntimeUtil {
4+
def isScala3(): Boolean = false
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.swagger.scala.converter
2+
3+
object RuntimeUtil {
4+
def isScala3(): Boolean = true
5+
}

src/test/scala/com/github/swagger/scala/converter/ModelPropertyParserTest.scala

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.swagger.scala.converter
22

3-
import com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospector
43
import io.swagger.v3.core.converter._
54
import io.swagger.v3.core.util.Json
65
import io.swagger.v3.oas.models.media._
@@ -107,10 +106,14 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
107106
val model = schemas.get("ModelWOptionInt")
108107
model should be (defined)
109108
model.value.getProperties should not be (null)
110-
val optInt = model.value.getProperties.get("optInt")
109+
val optInt = model.value.getProperties().get("optInt")
111110
optInt should not be (null)
112-
optInt shouldBe a [IntegerSchema]
113-
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
111+
if (RuntimeUtil.isScala3()) {
112+
optInt shouldBe a[ObjectSchema]
113+
} else {
114+
optInt shouldBe a[IntegerSchema]
115+
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
116+
}
114117
nullSafeList(model.value.getRequired) shouldBe empty
115118
}
116119

@@ -122,8 +125,12 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
122125
model.value.getProperties should not be (null)
123126
val optInt = model.value.getProperties().get("optInt")
124127
optInt should not be (null)
125-
optInt shouldBe a [IntegerSchema]
126-
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
128+
if (RuntimeUtil.isScala3()) {
129+
optInt shouldBe a[ObjectSchema]
130+
} else {
131+
optInt shouldBe a[IntegerSchema]
132+
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
133+
}
127134
optInt.getDescription shouldBe "This is an optional int"
128135
nullSafeList(model.value.getRequired) shouldBe empty
129136
}
@@ -136,7 +143,12 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
136143
model.value.getProperties should not be (null)
137144
val optInt = model.value.getProperties().get("optInt")
138145
optInt should not be (null)
139-
optInt shouldBe an [IntegerSchema]
146+
if (RuntimeUtil.isScala3()) {
147+
optInt shouldBe a[ObjectSchema]
148+
} else {
149+
optInt shouldBe a[IntegerSchema]
150+
optInt.asInstanceOf[IntegerSchema].getFormat shouldEqual "int32"
151+
}
140152
nullSafeList(model.value.getRequired) shouldEqual Seq("optInt")
141153
}
142154

@@ -148,27 +160,13 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
148160
model.value.getProperties should not be (null)
149161
val optLong = model.value.getProperties().get("optLong")
150162
optLong should not be (null)
151-
optLong shouldBe a [IntegerSchema]
152-
nullSafeList(model.value.getRequired) shouldBe empty
153-
}
154-
155-
//needs investigation
156-
it should "process Model with Scala Option Long (with jackson model override)" ignore {
157-
ScalaAnnotationIntrospector.registerReferencedValueType(
158-
classOf[ModelWOptionLong], "optLong", classOf[Long])
159-
try {
160-
val converter = ModelConverters.getInstance()
161-
val schemas = converter.readAll(classOf[ModelWOptionLong]).asScala.toMap
162-
val model = schemas.get("ModelWOptionLong")
163-
model should be (defined)
164-
model.value.getProperties should not be (null)
165-
val optLong = model.value.getProperties().get("optLong")
166-
optLong shouldBe a [IntegerSchema]
163+
if (RuntimeUtil.isScala3()) {
164+
optLong shouldBe a[ObjectSchema]
165+
} else {
166+
optLong shouldBe a[IntegerSchema]
167167
optLong.asInstanceOf[IntegerSchema].getFormat shouldEqual "int64"
168-
nullSafeList(model.value.getRequired) shouldBe empty
169-
} finally {
170-
ScalaAnnotationIntrospector.clearRegisteredReferencedTypes()
171168
}
169+
nullSafeList(model.value.getRequired) shouldBe empty
172170
}
173171

174172
it should "process Model with Scala Option Long with Schema Override" in {
@@ -350,7 +348,11 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
350348
stringsField shouldBe a[ArraySchema]
351349
val arraySchema = stringsField.asInstanceOf[ArraySchema]
352350
arraySchema.getUniqueItems() shouldBe (null)
353-
arraySchema.getItems shouldBe a[IntegerSchema]
351+
if (RuntimeUtil.isScala3()) {
352+
arraySchema.getItems shouldBe a[ObjectSchema]
353+
} else {
354+
arraySchema.getItems shouldBe a[IntegerSchema]
355+
}
354356
nullSafeMap(arraySchema.getProperties()) shouldBe empty
355357
nullSafeList(arraySchema.getRequired()) shouldBe empty
356358
}
@@ -368,8 +370,11 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
368370
val arraySchema = stringsField.asInstanceOf[ArraySchema]
369371
arraySchema.getUniqueItems() shouldBe (null)
370372

371-
372-
arraySchema.getItems shouldBe a[IntegerSchema]
373+
if (RuntimeUtil.isScala3()) {
374+
arraySchema.getItems shouldBe a[ObjectSchema]
375+
} else {
376+
arraySchema.getItems shouldBe a[IntegerSchema]
377+
}
373378
arraySchema.getItems.getDescription shouldBe "These are ints"
374379
nullSafeMap(arraySchema.getProperties()) shouldBe empty
375380
nullSafeList(arraySchema.getRequired()) shouldBe empty

src/test/scala/com/github/swagger/scala/converter/ScalaModelTest.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ class ScalaModelTest extends AnyFlatSpec with Matchers {
8585
val model = schemas("ModelWithIntVector")
8686
val prop = model.getProperties().get("ints")
8787
prop shouldBe a [ArraySchema]
88-
prop.asInstanceOf[ArraySchema].getItems.getType should be ("integer")
88+
val expectedType = if (RuntimeUtil.isScala3()) "object" else "integer"
89+
prop.asInstanceOf[ArraySchema].getItems.getType should be (expectedType)
8990
}
9091

9192
it should "read a model with vector of booleans" in {
9293
val schemas = ModelConverters.getInstance().readAll(classOf[ModelWithBooleanVector]).asScala
9394
val model = schemas("ModelWithBooleanVector")
9495
val prop = model.getProperties().get("bools")
9596
prop shouldBe a [ArraySchema]
96-
prop.asInstanceOf[ArraySchema].getItems.getType should be ("boolean")
97+
val expectedType = if (RuntimeUtil.isScala3()) "object" else "boolean"
98+
prop.asInstanceOf[ArraySchema].getItems.getType should be (expectedType)
9799
}
98100
}
99101

0 commit comments

Comments
 (0)